Greg Robinson's Blog

I report it, you decide

Click Once

Custom Authentication in Windows Forms

DataBinding Stuff

Favorite Links

My book contribution

My Book Reviews

My Personal Life

Richmond, VA .NET Users Group

Smart Client Stuff

What I am reading

Custom Exceptions, Inherit from what type?

I have heard ApplicationException. I have heard Exception.

From a MS source:

"......originally ApplicationException was intended to be derived from, however we've changed our tune on that one given how the hierarchy ended up developing. The new guidance is to derive directly from Exception in all cases where you would have derived from ApplicationException.  The guidelines on MSDN still have the old text. We will be updating  them, but probably not until after Whidbey goes out the door. As it  happens, there's some discussion of the issue here:

http://blogs.msdn.com/brada/archive/2004/03/25/96251.aspx.

"

Comments

Shital Shah said:

I wouldn't recommand inheriting directly from Exception all the time. The better approch is to declare base exception class for application. And then for each logical layer (or assembly), you can declare its own exception class. The heirarchy might look like..

MyAppException
MyDataException
MyBusinessException
MyBookBusinessException

The advantage of this scheme is that you can have generic application level handler (Application.ThreadException or custom error page in ASP.Net) or logging mechanism which you can tune for each type of exception you receive. This is effectivaely categorizing your exceptions.
# November 4, 2004 6:19 PM

Anon said:

Shital,

I think everyone agrees with your comment. The point is - what does the TOP level of the hierarchy inherit from? ApplicationException or Exception?

That is the question...
# November 4, 2004 6:55 PM

Jeff Atwood said:

ApplicationException is pointless. As stated above, don't use it. The other information is out of date.
# November 5, 2004 12:50 AM

TrackBack said:

Interesting Findings today
# November 5, 2004 8:06 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)