Error Question

  • Thread starter Thread starter MikeJ
  • Start date Start date
M

MikeJ

Hi Im Building a error handler application
i dont know how to check the type of exception in my
messageformat() Method
also id like to know if a method is in the exception
Errors Collection in SqlException

how can i check the type of exception and if the
exception object has a Method

Tia
MJ
 
MikeJ said:
Hi Im Building a error handler application
i dont know how to check the type of exception in my
messageformat() Method
also id like to know if a method is in the exception
Errors Collection in SqlException

how can i check the type of exception and if the
exception object has a Method

Tia
MJ

The System.Exception class should provide what you need.

http://msdn2.microsoft.com/en-us/library/system.exception_members.aspx

The getType() method and message property are good starting places.

Exception is the superclass for numerous exception types:

http://msdn2.microsoft.com/en-us/library/x4xzbdb9.aspx

If you catch Exception, you'll get a polymorphic reference to the actual
subtype.
 
Reflection will work. If you need to check specifically for
SqlException, it might be easier to do this:

// Assume the exception is in a variable named "exception".
SqlException sqlEx = exception as SqlException;

// If the variable is not null, then use it.
if (sqlEx != null)
{
// Work with sqlEx here.
}

Hope this helps.
 
cool thank you
MJ
Nicholas Paldino said:
Reflection will work. If you need to check specifically for
SqlException, it might be easier to do this:

// Assume the exception is in a variable named "exception".
SqlException sqlEx = exception as SqlException;

// If the variable is not null, then use it.
if (sqlEx != null)
{
// Work with sqlEx here.
}

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

pvdg42 said:
The System.Exception class should provide what you need.

http://msdn2.microsoft.com/en-us/library/system.exception_members.aspx

The getType() method and message property are good starting places.

Exception is the superclass for numerous exception types:

http://msdn2.microsoft.com/en-us/library/x4xzbdb9.aspx

If you catch Exception, you'll get a polymorphic reference to the actual
subtype.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top