Arne,
In addition to the other comments I normally use multiple Catch clauses. As
its "cleaner", something like:
Try
DoSomething()
Catch ex As SystemException
' got a system exception
Catch ex As ApplicationException
' got a application exception
Catch ex As Exception
' got another kind of exception
End Try
| Actually I would like to pass the
| variable of type Exception to a generic error handler, where I need to
know
| the specific Exception.
In the above case I may call an overloaded error handler, something like:
Sub ErrorHandler(ex As SystemException)
Sub ErrorHandler(ex As ApplicationException)
Sub ErrorHandler(ex As Exception)
Alternatively you could use a If/ElseIf/Else, something like:
Try
DoSomething()
Catch ex As Exception
If TypeOf ex Is SystemException Then
' got a system exception
ElseIf TypeOf ex Is ApplicationException Then
' got a application exception
Else
' got another kind of exception
End If
End Try
Of course the If/ElseIf/Else could be in its own routine. For example my
"Sub ErrorHandler(ex As Exception)" might have the If/ElseIf/Else to call
Sub ErrorHandler(ex As SystemException) to handle the exception...
Remember on both to list derived exceptions before base exceptions. As the
first class that matches is the handler that will be used.
Hope this helps
Jay
|I have a generic catch block for exceptions of type Exception
| Once inside the block I would like to know if my exception is of type
| System.Data.SqlClient.SqlException. Actually I would like to pass the
| variable of type Exception to a generic error handler, where I need to
know
| the specific Exception.
| I need to find a something like 'Is Type' or something like that.