How to tell which kind of exeption it is?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi, friends,

We have a common exception log function in C#:

public void LogException(System.Exception e)
{
.......//write error info to a file
}

which will log error message into a file. Sometiems, SqlException thrown
when using ADO.net will also be passed into this function.

I really want to log more info for those DB errors. However, how do I tell a
passed in exeption is a SqlExeption or other kind of exeptions?

Thanks a lot
 
Andrew said:
Hi, friends,

We have a common exception log function in C#:

public void LogException(System.Exception e)
{
.......//write error info to a file
}

which will log error message into a file. Sometiems, SqlException thrown
when using ADO.net will also be passed into this function.

I really want to log more info for those DB errors. However, how do I tell a
passed in exeption is a SqlExeption or other kind of exeptions?

Same way as you check for any other object's type - using either the
"as" operator or the "is" operator. (You could call GetType(), but
usually using "as" or "is" is the right way to go.)
 
Back
Top