Find Specific Exception to Catch.

J

joseph

Hi,
I have managed to use the try{} catch{(Exception e)} to catch all
exceptions that is happens in the application.

My application is an Active Directory Interface and need to report all
exceptions and handle them differently so I need to find out what code
to Class to use so I can act differently.

The first catch does not work and always goes to the second catch when
I supply wrong Username and password. I am thinking maybe I am using
the wrong class. How do I know which class to use???

For example:
catch (System.UnauthorizedAccessException e1)
{
StringBuilder lsb_TempString = new StringBuilder();
lsb_TempString.AppendFormat(@"My Exception: ");
lsb_TempString.AppendFormat("\n");
lsb_TempString.AppendFormat(@"BAD Username or password");
lsb_TempString.AppendFormat(e1.ToString());
throw(e1);
}
catch (System.Runtime.InteropServices.COMException e2)
{
StringBuilder lsb_TempString = new StringBuilder();
lsb_TempString.AppendFormat(@"My Exception: ");
lsb_TempString.AppendFormat("\n");
lsb_TempString.AppendFormat(@"BAD Domain Address");
lsb_TempString.AppendFormat(e2.ToString());
throw(e2);
}
catch (Exception e3)
{
StringBuilder lsb_TempString = new StringBuilder();
lsb_TempString.AppendFormat(@"My Exception: ");
lsb_TempString.AppendFormat("\n");
lsb_TempString.AppendFormat(@"Unknown Exception");
lsb_TempString.AppendFormat("\n");
lsb_TempString.AppendFormat(e3.ToString());
throw(e3);
}
 
R

Roman Wagner

Depending on the method u call you can catch different exceptions.
Take a look at the Documentation of the method u call, there u can find
a list of exception that can be thrown by the function. If u throw an
exception help other developers and provide this information in the xml
comment of your function.
 
J

joseph

Do you know where can I find a list of ALL (not commonly used)
exception classes so pick and choose which one to use.


Cheers
 

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

Similar Threads


Top