[RESOLVED] SELECT CASE on Exceptions
I have an exception object.
I want to do a select case to perform certain activities in cases when the exception is of a specific type.
So how would I structure such a SELECT CASE block?
For instance:
VB Code:
Select Case ex
Case System.StackOverflowException
Case System.ObjectDisposedException
End Select
Obviously, the above doesn't work but you get the idea...
Re: SELECT CASE on Exceptions
Build your try block to catch all the different kind of exceptions.
VB Code:
Try
catch exSO as StackOverflowException
'overflow occured
catch exOD as ObjectDisposedException
'etc etc
End Try
now youll know what exception occured.
Re: SELECT CASE on Exceptions
No, I can't use that method because the exception is passed into another procedure.
In other words, the place where I am interrogating the exception is not where the exception occurred (nor can that be helped).
Re: SELECT CASE on Exceptions
What you're asking for is not possible because the Select Case syntax doesn't support it. You can do this:
VB Code:
Select Case True
Case TypeOf ex Is StackOverflowException
Case TypeOf ex Is ObjectDisposedException
End Select
but that gains you nothing over regular If...ElseIf statements.
Re: SELECT CASE on Exceptions
Great thanks. That's just what I want.