Groups | Blog | Home
all groups > dotnet ado.net > march 2008 >

dotnet ado.net : exception GetType


John
3/15/2008 9:02:03 PM
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

Armin Zingler
3/15/2008 11:33:21 PM
"John" <info@nospam.infovis.co.uk> schrieb
[quoted text, click to view]

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
jp2msft
3/17/2008 6:54:01 AM
DirectCast.

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

Thanks!

[quoted text, click to view]
Phill W.
3/17/2008 1:38:37 PM
[quoted text, click to view]

Just as it does with any other Reference Type, GetType() returns you the
runtime Type of the object in question.

[quoted text, click to view]

[The Type of] /any/ class that inherits from System.Exception.
(Or System.Exception itself, of course).

[quoted text, click to view]

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

HTH,
AddThis Social Bookmark Button