Re: When to create your own exception class?



The actual point about exceptions is that they should:

- Provide a friendly message to the user in non-technical terms about what
happened, why and most important, how to recover from it
- A very detailed technical report to the developer, hidden behind a Details
button or included when sending a report.

So, if you don´t find a suitable exception in the framework to convey
specific information or to provide a detailed message with data (such as the
value that caused an "invalid argument" exception type), create a new
exception class and add it some properties. If you are rethrowing an
exception, you may want to encapsulate it (using the InnerException field)
to provide a better message or data, but don´t forget to include the inner
exception in the report that you receive as developer.

--
Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com

"Allan Ebdrup" <comaeb@xxxxxxxx> escribió en el mensaje
news:u$0jGP8eFHA.3032@xxxxxxxxxxxxxxxxxxxxxxx
> Hi
> I'm having a discussion with another programmer about a best practice for
> thrownig exceptions. I want to create a rich class library with many
> different exception classes in their own namespace, so they are easy to
> find with intellisense. He wants to just throw Exception or one of the
> build in exceptions. Do you have some good arguments for creating your own
> exception classes even though they are little more than a type strongname
> and the same as System.Exception (from witch they inherit)? We need the
> type strongname to write specific catch blocks right?
>
> Your input is appreciated.
>
> I've read about exceptions here:
>
> http://www.codeproject.com/dotnet/exceptionbestpractices.asp
>
> http://www.ftponline.com/vsm/2003_05/online/wagner/
>
> http://www.codeguru.com/Csharp/Csharp/cs_syntax/errorhandling/article.php/c8605/
>
> http://www.dotnetspider.com/technology/kbpages/931.aspx
>
> http://www.dotnetspider.com/technology/kb/ShowSample.aspx?SampleId=933
>
> http://www.ondotnet.com/pub/a/dotnet/2001/09/04/error_handling.html
>
> http://www.c-sharpcorner.com/Articles/ExceptionHandlingInCSKS004.asp
>
> http://vsdntips.com/download/dotNet%20Coding%20Standards-sample.pdf
>
> http://smccd.net/accounts/tilmann/cis_391_392/Slides/S_Handout%20S7.pdf
>
> http://builder.com.com/5100-6387-1045391.html
>
> http://www.javaspecialists.co.za/archive/Issue089.html
>
> http://www.c2.com/cgi/wiki?ConvertExceptions
>
> http://www.c2.com/cgi/wiki?JavaIdioms
>
> http://www.javaworld.com/javatips/jw-javatip91_p.html
>
> http://www.onjava.com/pub/a/onjava/2003/11/19/exceptions.html
>
> http://www.onjava.com/pub/a/onjava/2004/09/29/smtp-logging.html?page=1
>
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vclrfusingstatement.asp
>
>
>
> Kind Regards,
> Allan Ebdrup
>


.


Loading