Re: Newbie: try, catch problem
From: Mikael Gustavsson ("Mikael)
Date: 02/24/04
- Next message: John Timney \(Microsoft MVP\): "Re: The New Linux Economy"
- Previous message: reiks: "newbie .net"
- In reply to: Sam Henson: "Newbie: try, catch problem"
- Next in thread: Bjorn Abelli: "Re: Newbie: try, catch problem"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 24 Feb 2004 13:04:50 +0100
Hi Sam!
If you just add a MessageBox.Show(test.ToString()) after you have done the
parse you will see why no exception is thrown.
When I did what you did and displayed the result this is what I got
192.0.0.168
It seems is if the pattern is like this
IPAddress.Parse("192");
Result = 0.0.0.192
IPAddress.Parse("192.168");
Result = 192.0.0.168
IPAddress.Parse("192.168.2");
Result = 192.168.0.2
And finally
IPAddress.Parse("192.168.2.1");
Result = 192.168.2.1
Why it works this way I have no clue. It would seem logical that it should
have been
192.168.0.0 instead of 192.0.0.168 but logic and real life does not always
compute :)
Good luck anyway!
//Mikael
"Sam Henson" <anonymous@discussions.microsoft.com> wrote in message
news:2534CD88-E5B6-4260-822D-7A44C3728AA0@microsoft.com...
> Hi!
>
> the following code should throw an exception, but it doesn't! can anyone
tell me why?
>
> try
> {
> IPAddress test = IPAddress.Parse("192.168"); //invalid input
> }
> catch(Exception mye)
> {
> MessageBox.Show("error");
> return;
> }
>
> Any ideas?
>
> Sam Henson
- Next message: John Timney \(Microsoft MVP\): "Re: The New Linux Economy"
- Previous message: reiks: "newbie .net"
- In reply to: Sam Henson: "Newbie: try, catch problem"
- Next in thread: Bjorn Abelli: "Re: Newbie: try, catch problem"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|