"Kirk" <lo****@hotmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
I tried to use the properties of the Exception object, but I could not
find one that shows a unique identifier (like an error number).
That's because you don't [iften] need one. The *Type* of the
Exception itself tells you what went wrng, which is why you tend to
see Catch blocks like this
Try
SomethingDodgy()
Catch ex as ReallySpecificTypeOfException
Recover()
Catch ex as SomeOtherTypeOfException
Giveup()
Catch ex as EvenMoreGenericException
Throw
' or, possibly, even
Catch ex as System.Exception
If TypeOf ex Is ArgumentException Then
OhDearYouDidSomethingWrong()
Else
Throw
End If
End Try
Notice that your Catch'es have to be "in order", catching the
"smallest" Exception first, i.e. the one "most" derived from
System.Exception. Check the Class hierarchy for each Exception
in MSDN; the /fewer/ levels it is away from System.Exception, the
earlier you should code to catch it. Beware:
Try
Catch ex as Exception
' /Always/ arrives here
Catch ex as ArgumentException
' *Never* arrives here
End Try
BTW, *some* Exceptions, like the COMException, /do/ have a
numeric ErrorCode property (which, inthis case, holds the errant
HResult), but you only get these thrown by methods that "call out"
to COM. Managed Code doesn't do this so no error "number" is
necessary.
HTH,
Phill W.