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

Re: exception GetType by Armin

Armin
Sat Mar 15 17:33:21 CDT 2008

"John" <info@nospam.infovis.co.uk> schrieb
> 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


Re: exception GetType by Phill

Phill
Mon Mar 17 08:38:37 CDT 2008

John wrote:

> 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.

Re: exception GetType by jp2msft

jp2msft
Mon Mar 17 08:54:01 CDT 2008

DirectCast.

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

Thanks!

"Phill W." wrote:

> John wrote:
>
> > 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.
>