473,394 Members | 1,726 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,394 software developers and data experts.

General questions on exceptions


In general how do you indentify a specific error? If 2 different error
conditions throw the same type of exception how do you know which error
occured? There are no error numbers, so are you forced to compare
Message strings? But these strings are locale dependent, so that
wouldn't work.

Also, is there a complete table or listing of possible framework errors?
I've never seen one.
Nov 17 '05 #1
3 1117
Paul <---@---.---> wrote:
In general how do you indentify a specific error? If 2 different error
conditions throw the same type of exception how do you know which error
occured? There are no error numbers, so are you forced to compare
Message strings? But these strings are locale dependent, so that
wouldn't work.

Also, is there a complete table or listing of possible framework errors?
I've never seen one.


In general, you shouldn't need to rely on anything more specific than
the type of exception. Unfortunately, that's not always the case -
sometimes the same exception is given for different reasons, one of
which you can handle and one of which you can't. There's no good,
reliable way of determining the difference.

The only complete listing of possible framework exceptions is the one
you get by looking at the MSDN docs for Exception, and look for all the
derived classes.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 17 '05 #2
There is one situation that you can do something about. If you are
having to distinguish between two exceptions coming out of one of your
own routines, but which originate in two different calls down to the
..NET Framework, you can catch each of them in your code and "wrap" them
in different exceptions so that you can distinguish them.

For example, if you have a method:

public void DoSomethingOrOther(object param1, object param2)
{
// Call a Framework method with param1
FrameworkMethod1(param1);

// Call a Framework method with param2
FrameworkMethod2(param2);
}

Now, either of these calls could throw an ArgumentNullException, if one
of param1 or param2 was null. Which framework method throws the
exception depends upon which argument is null. From the outside of
DoSomethingOrOther, the two exceptions are indistinguishable. However,
you could change that by doing this:

public void DoSomethingOrOther(object param1, object param2)
{
try
{
// Call a Framework method with param1
FrameworkMethod1(param1);
}
catch (ArgumentNullException ane)
{
throw new MyApplicationException("Something-or-other can't be
null.", ane);
}

// Call a Framework method with param2
FrameworkMethod2(param2);
}

Now you can distinguish the (recoverable) condition of the first
parameter being null from the (unrecoverable) condition of the second
parameter being null.

Of course, this works only in this circumstance. It doesn't work if a
single Framework method happens to throw the same exception under two
different conditions, and you want to recover from one and not the
other. In that case, you're out of luck. :(

Nov 17 '05 #3
> Of course, this works only in this circumstance. It doesn't work if a
single Framework method happens to throw the same exception under two
different conditions, and you want to recover from one and not the
other. In that case, you're out of luck. :(


This is my problem -- the framework provides no way to narrow down the
error in some cases. But it's true that usually the exception type is
all you need.

I found today that in the case of SocketException the error has detailed
socket error codes returned from the underlying API. I just wish all the
exceptions had a unique code number you could look up. I feel very old
school.

Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: amit | last post by:
Hello, I am currently studying how to embedd python. I am developing a graphical C++ application. My goal is to embedd python script that will control some kind of animation. I have some...
9
by: pankaj_wolfhunter | last post by:
Hi, I need some clearance on the following questions: 1) Does LOAD command updates indexes defined for a table? 2) Is REPLACE option in the LOAD command a logged operation? Help will be...
3
by: Steve | last post by:
I have some general catch clauses in my app as follows: try { } catch(Exception ex) { } try
1
by: jason | last post by:
Hello everyone, I have some general questions about the DataTable object, and how it works. Moderately new to C#, I have plenty of texts describing the language, but not so much to reference...
2
by: Eric Sabine | last post by:
I built a generic exception handler form which allows the user to get information from it, print it, email it, etc. for exceptions for which I explicitly didn't handle in code, such as missing...
20
by: Cyn | last post by:
Hi, I want to create a general array structure which can hold all types. Something like this: struct ARRAY { void **array; size_t size; };
2
by: pack | last post by:
"Unless you have a very good reason to catch an exception, DON'T. Exceptions are supposed to be exceptional, just like the dictionary meaning: uncommon, unusual. When in doubt, let the calling...
6
by: john_c | last post by:
FxCopy says this about catching general exceptions: "You should not catch Exception or SystemException. Catching generic exception types can hide run-time problems from the library user, and can...
5
by: Soumen | last post by:
For one of my project, I want to use auto_ptr. But I'm facing few issues. 1. Say I've Controller class. I don't want to allow user to create object of this class unless all arguments are valid....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.