![]() ![]() Lastly, you'll find that, especially when you use this technique, it's best to enable the compiler warning for overlapping catch blocks. ![]() You'll find though, that the TypeOf syntax is more elegant. Lastly, to get a System.Type object for a class without instantiating it use VBs GetType operator e.g. You can then put in other catch blocks with different filers or a last catch block with no filter to catch any unspecified PingExceptions.įeel free to use the When clause in VB.NET because it's cool. Would probably be overkill as if InnerException Is Nothing the TypeOf operation will return False and the catch block won't be executed. "When pEx.InnerException IsNot Nothing AndAlso TypeOf pEx.InnerException Is SocketException" ![]() To compare the type of a single variable you needn't instantiate a second.Ĭatch pEx As PingException When TypeOf pEx.InnerException Is SocketException Reply = pinger.Send("some_pc_name_or_IP_address")Ĭatch ex As For example:ĭim pinger As = New ĭim reply As You'll want to use some exception handling with Try/Catch blocks in order to test for the exceptions. It is probably a socket exception indicating an unknown hostname. If you get that, look at the InnerException. The one you are probably getting is (VS.80).aspx. HostNameOrAddress could not be resolved to a valid IP address. See the inner exception for the exact exception that was thrown. HostNameOrAddress is a null reference (Nothing in Visual Basic) or is an empty string ("").Īddress is an IPv6 address and the local computer is running an operating system earlier than Windows 2000.Īn exception was thrown while sending or receiving the ICMP messages. Ping.Send() can throw several exceptions. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
December 2022
Categories |