Hi Sam,

I seem to remember Effective Java has some great Idioms for Exception
handling.

I try create Application exceptions where possible, and inherit all of an
application's (or library's) exceptions from this application level
exception.  Allows for generic catching of all exceptions thrown by my
application.

The other idea I've seen which I think is quite useful is the advise that
you should translate low-level exceptions into higher business logic
exceptions.  For example InvalidOperationException from some deep method
might not mean much, but FailedFundsTransferException might.

I also like to log all exceptions, which I use Log4NET, which lets you set
configuration, and log standard error levels, such as warm, info, debug,
etc.  Depending on priority these can then be sent to specified sources such
as mail, Console, event log, etc.

You might also check out the Microsoft Exceptions Application Block.

Hope this is of some help,

Duncan

----- Original Message -----
From: "Sam Gentile" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, May 28, 2002 8:38 PM
Subject: [DOTNET] Need a good real-world C# Exceptions Resource or Stategy
for Library


> I have just been poring through C# books and no one seems to address this
> well. Sure, otherwise great books like Jesse Liberty's "Progarmming C#"
talk
> about Exceptions but all the examples are too trivial. The examples just
> shoot out an "I am here" kind of thing in the catch handler. Actually some
> C# books don't even discuss it!! I need something more.
>
> Lets suppose I am/have creating a C# library of classes in a namespace. I
> want to put in full exception handling. I have some circumstances where I
am
> creating files and reading them with System.IO classes, I am doing a lot
of
> things with System.Xml. The thing is that I want to define and implement a
> sound exception processing strategy. Obviously, I don't really want to
> handle exceptions in a library by putting up
System.Console.WriteLine("Can't
> open file"). I want to throw them up to the caller, but what? Suppose I
> catch an ArgumentNullException on a FileStream constructiuon. Does it make
> sense to define my custom exceptions and throw those up? Are there any
good
> C# resources that show real exception processing/good pratices?
>
>
>
> ---------------------
> Sam Gentile
> .NET Consultant
> Co-author: Wrox Visual C++ .NET: A primer for C++ developers
> BLOG: http://radio.weblogs.com/0105852/
> http://www.project-inspiration.com/sgentile/DotNet.htm
> http://www.project-inspiration.com/sgentile/
> ---------------------------
>
>
>
>
> _________________________________________________________________
> Chat with friends online, try MSN Messenger: http://messenger.msn.com
>
> You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
> subscribe to other DevelopMentor lists at http://discuss.develop.com.

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to