473,390 Members | 1,153 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,390 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 3586
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Professor Frink | last post by:
First off, I apologize if this gets long. I'm simply trying to give you all enough information to help me out. I'm writing (almost finished, actually), my first VB.Net application. It's a forms...
3
by: needin4mation | last post by:
I'm writing c# asp.net. I have a dataset loading when the page loads and it has an itemdatabound event. When there is an error in the itemdatabound event I get the catch in the calling...
5
by: cj | last post by:
When I run myMAPIMessage.Send(True) if the user cancels the resulting email it causes an exception. How do I trap this particular exception and say that's ok? try myMAPIMessage.Send(True)...
7
by: Sek | last post by:
Hi Folks! I was pondering over a code and noticed that exception handlers were present in the private, protected as well as public methods. And, ofcourse, public methods were calling priv/prot...
12
by: TS | last post by:
If I was to have my biz layer ask the data layer to load a particular object based on key field info i pass to it, and it cannot create the object becaues it isnt' in the Db, should the data layer...
11
by: greg | last post by:
I have been struggling with the following issue: How can one find the type of the exception? In other words I would likes to come up with piece of code that does the following (written in pseudo...
11
by: Mick Walker | last post by:
How can I find the name of the current function being executed. For example, lets say I have the following function void Blah(int? y){ int z; try { z = y; } catch(Exception ex){
9
by: JoeP | last post by:
Hi All, How can I find the reason for such an error: Failure sending mail. Some Code... oMailMessage.IsBodyHtml = False oMailMessage.Body = cEmailBody Dim oSMTP As New SmtpClient...
2
by: karinmorena | last post by:
I'm having 4 errors, I'm very new at this and I would appreciate your input. The error I get is: Week5MortgageGUI.java:151:cannot find symbol symbol: method allInterest(double,double,double)...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.