Tuesday 30 October 2007

The type of a vb.net Object

If you need to find verify that an object is of a specific type it can be done in the following way:

If TypeOf Err.GetException() Is DHEException Then

This uses the keyword "TypeOf" and "Is" I have used it to make sure that the exceptions, catched though the bad "On Error" statement, is still handled and the correct error code is returned.


If Err.Number <> 0 Then
If TypeOf Err.GetException() Is DHEException Then
Dim ex As DHEException = Err.GetException
cerr = ex.dheErr
Else
cerr = -(1000000 + Err.Number)
End If
errMsg += "|ExecService:" + Err.Description + " " + Err.GetException.StackTrace
log.Error(errMsg)
End If

2 comments:

Anonymous said...

Bravo, brilliant idea

Anonymous said...

Ask, and it shall be given to you; seek, and you shall find it; knock, and it shall be opened unto you.