With the libraries we create, we try to make the exceptions that a library client receives meaningful. This often means that we need to wrap up internal sql / xml / io exceptions into an UnknownPersonException (etc...)
Also, we find it extremely useful to XML-Doc the exceptions that each method in our library calls, so that the client knows that they are catching all meaningful application exceptions: /// <exception cref="UnknownPersonException">If the person cannot be found</exception> Kirk -----Original Message----- From: franklin gray [mailto:[EMAIL PROTECTED]] Sent: Wednesday, 29 May 2002 9:37 a.m. To: [EMAIL PROTECTED] Subject: Re: [DOTNET] Need a good real-world C# Exceptions Resource or Stategy for Library It's the same thing, whether your creating the UI or somebody else is. libraries don't log and don't handle exceptions, except ones that are part of your process, such as (don't know if it's the same in dotnet, I haven't tried it yet) common dialog, when the user presses cancel, that would raise an error. Of course you wouldn't want to pass that error on to the caller, so you would catch that one. Any exception that you don't plan on catching, just re-raise the exception to pass it on to the caller. In most library code, you will not try/catch anything. That's up to the caller. -----Original Message----- From: Sam Gentile [mailto:[EMAIL PROTECTED]] Sent: Tuesday, May 28, 2002 4:25 PM To: [EMAIL PROTECTED] Subject: Re: [DOTNET] Need a good real-world C# Exceptions Resource or Stategy for Library That's too simplistic. I don't have a GUI app. I am creating a reusable set of classes in a library that I want to have intelligent exception hadling for. Its more like what Graeme understood in his reply. >From: franklin gray <[EMAIL PROTECTED]> >Reply-To: dotnet discussion <[EMAIL PROTECTED]> >To: [EMAIL PROTECTED] >Subject: Re: [DOTNET] Need a good real-world C# Exceptions Resource or > Stategy for Library >Date: Tue, 28 May 2002 14:51:36 -0500 > >I really don't understand what you are missing but this is the way I >would look at it for a Desktop app. > >Do this in the UI where events start, not in dll's or class unless you >need to trap an error. > >Try > execute stuff >Catch > show the error to the user by either a messagebox or a custom >display form (this can include a cut and paste button and/or an email >button to email support), and log the error in a text file (xml text >file if your hightech). finally > handle things like cursors. > > >for you custom errors, create your own exceptions in a sererate dll and >any assembly that needs one, just reference the dll. Then you can >easily create your custom exceptions and catch them later. > > > >-----Original Message----- >From: Sam Gentile [mailto:[EMAIL PROTECTED]] >Sent: Tuesday, May 28, 2002 2:38 PM >To: [EMAIL PROTECTED] >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. --------------------- 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/ --------------------------- _________________________________________________________________ Send and receive Hotmail on your mobile device: http://mobile.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. You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com.