473,467 Members | 1,507 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

The recommended approach to the none-of-the-above exception?

apa
There are a few well-known (?) guidelines to throwing/creating exceptions
(paraphrasing my understanding of it):
1. Don't throw general types like Exception or ApplicationException.
2. Use existing exception classes where it makes sense (ArgumentException
etc).
3. Don't create custom exception types if they don't add anything of value.
(Value can be just being able to catch that exception and nothing else.)

However, where I get confused is where I don't have any specific information
to add about an exception, and don't expect any special exception handling
to occur. For example, say I do a database query, which very unexpectedly
returns an empty result set. I basically just want to

throw new Exception("no data from db");

FxCop will have issues with that though. Should I create a
"MyApplicationException" for the none-of-the-above stuff? It seems to break
rule #3.

Thanks!
Oct 7 '08 #1
1 1058
apa <ap*@apa.comwrote:
There are a few well-known (?) guidelines to throwing/creating exceptions
(paraphrasing my understanding of it):
1. Don't throw general types like Exception or ApplicationException.
2. Use existing exception classes where it makes sense (ArgumentException
etc).
3. Don't create custom exception types if they don't add anything of value.
(Value can be just being able to catch that exception and nothing else.)

However, where I get confused is where I don't have any specific information
to add about an exception, and don't expect any special exception handling
to occur. For example, say I do a database query, which very unexpectedly
returns an empty result set. I basically just want to

throw new Exception("no data from db");

FxCop will have issues with that though. Should I create a
"MyApplicationException" for the none-of-the-above stuff? It seems to break
rule #3.
No, because of the bit in brackets - the type itself (e.g.
MissingDataException) would be useful information. You don't even need
to explicitly catch it for it to be of use - you might choose to break
into code when debugging as soon as that is thrown.

If it feels a bit specific to you, think about an exception which you
can use whenever the database is in an unexpected state -
"UnexpectedDatabaseStateException" or something similar.

--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
Oct 7 '08 #2

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

Similar topics

35
by: Steven Bethard | last post by:
I have lists containing values that are all either True, False or None, e.g.: etc. For a given list: * If all values are None, the function should return None.
5
by: Daniel Crespo | last post by:
Is there a built-in method for transforming (1,None,"Hello!") to 1,None,"Hello!"? Thanks
11
by: Hasan O | last post by:
Hi , i have problem about sending data over socket . It waits for another socket.send // str = Encoding.ASCII.GetBytes("hello"); socket.Send(str,0,str.Length,SocketFlags.None); ...
1
by: VK | last post by:
Recommended upgrade from 8.51 to 8.52: <http://www.opera.com/download/index.dml?custom=yes> Change log: <http://www.opera.com/docs/changelogs/windows/852/>
16
by: Luqman | last post by:
Is it recommended to use datasets in ASP.Net 2.0 / VS.Net 2005 ? Best Regards, Luqman
5
by: Joe Van Dyk | last post by:
After reading K&R, is there any other good source for learning how to write good C programs? I've heard a reference to one other highly-recommended book, but I forget what it was. C++ has all...
4
by: BartlebyScrivener | last post by:
How do you test for a function that returns nothing, and why doesn't this work? Shouldn't X have to be either None or not? >>>x = None >>> for x in : .... if x is None: .... print "X is...
8
by: micklee74 | last post by:
hi i wish to map None or "None" values to "". eg a = None b = None c = "None" map( <something> , if i in ("None",None) ]) I can't seem to find a way to put all values to "". Can anyone...
3
by: Ge Chunyuan | last post by:
hi Group: I am a new comer for Python, I wonder which IDE is recommended in Windows OS. Can anyone give some suggestion. Thanks indeed Ge Chunyuan
7
by: Jack | last post by:
Any recommended books on PHP-MYSQL with serious examples in c++? Regards Jack
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
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
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
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
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...

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.