473,805 Members | 1,896 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1133
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.co m>
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 DoSomethingOrOt her(object param1, object param2)
{
// Call a Framework method with param1
FrameworkMethod 1(param1);

// Call a Framework method with param2
FrameworkMethod 2(param2);
}

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

public void DoSomethingOrOt her(object param1, object param2)
{
try
{
// Call a Framework method with param1
FrameworkMethod 1(param1);
}
catch (ArgumentNullEx ception ane)
{
throw new MyApplicationEx ception("Someth ing-or-other can't be
null.", ane);
}

// Call a Framework method with param2
FrameworkMethod 2(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
1923
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 questions about python embedding: 1) Is there a good text book or other resource on embedding/extending? (I find it hard to learn only by the tutorial and C/Python API from the python.org site)
9
1704
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 greatly appreciated. TIA
3
2896
by: Steve | last post by:
I have some general catch clauses in my app as follows: try { } catch(Exception ex) { } try
1
1807
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 ADO.NET objects (only the MSDN help files). I have written a C# Class Library that is responsible for encapsulating database information. All the objects work just fine for singleton record insert, update, select, and delete operations. But now we...
2
1309
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 permissions on a stored procedure, etc. I use this exception handler in all of my applications and it can be called as simply as follows try ... catch ex as sqlexception ExceptionHandler(ex, otherData1, otherData2)
20
2332
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
1207
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 routine, or the global exception handler, deal with it. This is the golden rule. The hardest kinds of exceptions to troubleshoot are the ones that don't even exist, because a developer upstream of you decided to consume it." What's "global...
6
1932
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 complicate debugging. You should catch only those exceptions that you can handle gracefully." This is for a winform app but applies to asp.net also. There are some code blocks you may know which exception may get thrown and others
5
1725
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. So I've made the constructor private and given one static method to create an object of this class. Since one of senior members in the team doesn't like throwing exception, I've made this static method to return NULL pointer when arguments are...
0
9716
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10609
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10360
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10366
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10105
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5542
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4323
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3845
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.