471,594 Members | 2,045 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,594 software developers and data experts.

Find Specific Exception to Catch.

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);
}

Nov 29 '06 #1
3 3511
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.

jo****@copticmail.com schrieb:
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);
}
Nov 29 '06 #2
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

Nov 30 '06 #3
Hmm, don't know where your problem is.

For example if u use File.Open take a look at
http://msdn2.microsoft.com/en-us/library/b9skfh7s.aspx
to get a list of all exceptions that can be thrown by invoking this
method.
jo****@copticmail.com schrieb:
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
Nov 30 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Professor Frink | last post: by
5 posts views Thread by cj | last post: by
11 posts views Thread by greg | last post: by
11 posts views Thread by Mick Walker | last post: by
2 posts views Thread by karinmorena | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by Anwar ali | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.