exception GetType

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi

What is the purpose of exception.GetType and what are the possible values
returned by it? Can it for example tell me if the exception is of type
DBConcurrencyException?

Thanks

Regards
 
John said:
Hi

What is the purpose of exception.GetType and what are the possible
values returned by it? Can it for example tell me if the exception
is of type DBConcurrencyException?

GetType is inherited from Object. It returns the System.Type object
representing the instance type of the object. To check for a certain
type, use the TypeOf keyword (if typeof ex is DBConcurrencyException
then). If you want to catch different types of exceptions and handle
them differently, you can write:

try

catch ex as DBConcurrencyException
'...
catch ex as WhateverException
'...
catch ex as exception
'...
end try


Armin
 
John said:
What is the purpose of Exception.GetType

Just as it does with any other Reference Type, GetType() returns you the
runtime Type of the object in question.
and what are the possible values returned by it?

[The Type of] /any/ class that inherits from System.Exception.
(Or System.Exception itself, of course).
Can it for example tell me if the exception is of type
DBConcurrencyException?

If TypeOf ex Is DBConcurrencyException Then
With DirectCast( ex, DBConcurrencyException )
' Use exception
End With
End If

HTH,
Phill W.
 
DirectCast.

There is something new that I've learned today, and I've just added to my
book of spells.

Thanks!

Phill W. said:
John said:
What is the purpose of Exception.GetType

Just as it does with any other Reference Type, GetType() returns you the
runtime Type of the object in question.
and what are the possible values returned by it?

[The Type of] /any/ class that inherits from System.Exception.
(Or System.Exception itself, of course).
Can it for example tell me if the exception is of type
DBConcurrencyException?

If TypeOf ex Is DBConcurrencyException Then
With DirectCast( ex, DBConcurrencyException )
' Use exception
End With
End If

HTH,
Phill W.
 
Back
Top