Click here to Skip to main content
15,886,055 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
GeneralRe: When to Define a Custom Exception PinPopular
Not Active14-Jan-11 3:00
mentorNot Active14-Jan-11 3:00 
GeneralRe: When to Define a Custom Exception Pin
#realJSOP14-Jan-11 3:38
mve#realJSOP14-Jan-11 3:38 
GeneralRe: When to Define a Custom Exception Pin
Yusuf14-Jan-11 4:28
Yusuf14-Jan-11 4:28 
GeneralRe: When to Define a Custom Exception Pin
Eddy Vluggen14-Jan-11 11:54
professionalEddy Vluggen14-Jan-11 11:54 
GeneralRe: When to Define a Custom Exception Pin
Daniel Turini15-Jan-11 23:28
Daniel Turini15-Jan-11 23:28 
AnswerRe: When to Define a Custom Exception Pin
Single Step Debugger14-Jan-11 3:14
Single Step Debugger14-Jan-11 3:14 
AnswerRe: When to Define a Custom Exception Pin
HimanshuJoshi14-Jan-11 4:39
HimanshuJoshi14-Jan-11 4:39 
AnswerRe: When to Define a Custom Exception Pin
Ray Cassick14-Jan-11 6:24
Ray Cassick14-Jan-11 6:24 
My decision is to define a custom exception when the need to do so is... well... exceptional Smile | :)

Really though…

If you have an exception definition that clearly fits an existing model then use it, why reinvent the wheel at all?

If you are creating a new failure state, usually most likely based upon things like a domain specific business rule, then you define a new exception of your own design. BUT you have to keep in mind that quite often even doing this can cause issues because as we all know business rules change. This means that you may want to be slightly less specific and more generalized by defining a business rule exception and allowing it to express the rule broken, and the why it was considered broken enough to trigger the exception.

I would like to know what books you say are specifically stating that new exceptions should always be defined instead of using the Dotnet ones. I would have to have a conversation with that author Smile | :) I am not even sure I see the value in writing all custom exceptions when creating a whole new code library of your new library is something that sits on top of the Dotnet framework. If you are writing something that is completely disconnected at all form the Dotnet stuff then yeah, you have to create your own exceptions to throw, but that makes no sense in this context really since your question was more related to being told to not use Dotnet exceptions Smile | :) .

If you did want to keep all the exceptions specific to your application layer then there is nothing from stopping you from writing all your own custom exception code, but I would still recommend that you consider catching the Dotnet specific stuff and then just re throwing your own as a general application side exception and then include the Dotnet exception in that object. Seems a bit messy but I guess it is doable and will not require too much writing on your part. Just remember that every additional line of code you have to write can possibly introduce a new error (and thus CAUSE an exception Smile | :) ) so I like to keep them down to a minimum.

One other argument I would make for maintaining the existing exceptions provided by the framework is that anytime they change you need to ensure that your code changes also. This means that if you have wrapped all of the Dotnet exceptions in your code, any time the framework changes you have to review all those changes to see what effects they have on your code. Not that you may not have to do the same if the base libraries change their exceptions and you have to catch them, but usually one of a few things happen there. First, they will keep the older exception around for a while tagged in the new framework that it is being pulled soon so that new code compilation will not allow the use of it but existing code can still use it, and second you have some time to make changes. This is also a good reason to always be sure to include a general catch statement if you want to be sure that you can grab any problems that come up due to your missing a specific exception that perhaps is not well documented or you just missed.

Whew.. a long response…

AnswerRe: When to Define a Custom Exception Pin
Patrick Fox14-Jan-11 6:50
Patrick Fox14-Jan-11 6:50 
AnswerRe: When to Define a Custom Exception Pin
RobCroll14-Jan-11 21:21
RobCroll14-Jan-11 21:21 
AnswerRe: When to Define a Custom Exception Pin
Patrick Skelton14-Jan-11 22:39
Patrick Skelton14-Jan-11 22:39 
GeneralRe: When to Define a Custom Exception Pin
Pete O'Hanlon15-Jan-11 4:20
mvePete O'Hanlon15-Jan-11 4:20 
AnswerRe: When to Define a Custom Exception Pin
dan!sh 15-Jan-11 2:35
professional dan!sh 15-Jan-11 2:35 
AnswerRe: When to Define a Custom Exception Pin
Robert Tanenbaum28-Jan-11 4:20
Robert Tanenbaum28-Jan-11 4:20 
GeneralRe: When to Define a Custom Exception Pin
Patrick Skelton28-Jan-11 6:00
Patrick Skelton28-Jan-11 6:00 
QuestionIs it Possible to build a Processor which understands MSIL code. PinPopular
vytheese13-Jan-11 0:46
professionalvytheese13-Jan-11 0:46 
AnswerRe: Is it Possible to build a Processor which understands MSIL code. Pin
Pete O'Hanlon13-Jan-11 0:51
mvePete O'Hanlon13-Jan-11 0:51 
GeneralRe: Is it Possible to build a Processor which understands MSIL code. Pin
vytheese13-Jan-11 0:59
professionalvytheese13-Jan-11 0:59 
GeneralRe: Is it Possible to build a Processor which understands MSIL code. Pin
Pete O'Hanlon13-Jan-11 1:02
mvePete O'Hanlon13-Jan-11 1:02 
GeneralRe: Is it Possible to build a Processor which understands MSIL code. Pin
vytheese13-Jan-11 1:12
professionalvytheese13-Jan-11 1:12 
GeneralRe: Is it Possible to build a Processor which understands MSIL code. Pin
Rob Grainger13-Jan-11 22:38
Rob Grainger13-Jan-11 22:38 
GeneralRe: Is it Possible to build a Processor which understands MSIL code. Pin
Wesley Harris16-Jan-11 22:16
Wesley Harris16-Jan-11 22:16 
GeneralRe: Is it Possible to build a Processor which understands MSIL code. Pin
peterchen14-Jan-11 1:57
peterchen14-Jan-11 1:57 
AnswerRe: Is it Possible to build a Processor which understands MSIL code. Pin
Luc Pattyn13-Jan-11 1:43
sitebuilderLuc Pattyn13-Jan-11 1:43 
GeneralRe: Is it Possible to build a Processor which understands MSIL code. Pin
vytheese13-Jan-11 2:25
professionalvytheese13-Jan-11 2:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.