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

.NET (Core and Framework)

 
GeneralRe: When to Define a Custom Exception Pin
Dan Neely14-Jan-11 3:03
Dan Neely14-Jan-11 3:03 
GeneralRe: When to Define a Custom Exception Pin
Daniel Turini14-Jan-11 5:21
Daniel Turini14-Jan-11 5:21 
GeneralRe: When to Define a Custom Exception Pin
Dan Neely14-Jan-11 5:28
Dan Neely14-Jan-11 5:28 
GeneralRe: When to Define a Custom Exception Pin
Daniel Turini14-Jan-11 6:17
Daniel Turini14-Jan-11 6:17 
GeneralRe: When to Define a Custom Exception Pin
Eddy Vluggen14-Jan-11 12:19
professionalEddy Vluggen14-Jan-11 12:19 
AnswerRe: When to Define a Custom Exception Pin
Aamir Butt14-Jan-11 0:58
Aamir Butt14-Jan-11 0:58 
AnswerRe: When to Define a Custom Exception PinPopular
Abhinav S14-Jan-11 1:08
Abhinav S14-Jan-11 1:08 
AnswerRe: When to Define a Custom Exception PinPopular
Gary Wheeler14-Jan-11 1:11
Gary Wheeler14-Jan-11 1:11 
If the condition that triggers the exception is reasonably generic (a null argument, or a value out of range), I use one of the predefined .NET exceptions. If the condition is domain-specific to the application, then I define my own.

For example, I have a class that handles TCP/IP socket communications between my application and a Windows service. This class can throw InvalidCastExceptions, given that our protocol includes data type information along with each data value in a message. This ensures that the sender/receiver on my end agrees with the receiver/sender on the other end. It also can throw BufferException or ReadSizeException, exceptions defined in the class derived from ApplicationException, that reflect protocol errors.

Patrick Skelton wrote:
According to some books I have read, the exceptions built into .NET should generally be reserved for .NET's own use and developers should create custom exceptions for classes they create.


This is symptomatic of an 'anti-pattern' you see occasionally. Some programmers think that they always have to insulate their applications from potential changes to the framework they're using. They build wrapper classes for everything. The wrappers end up being extremely thin layers on top of the actual framework. All they accomplish with this is to obfuscate their use of the framework. This makes their code more difficult to debug and maintain, since they rarely document framework considerations and constraints that their wrapper promotes.
Software Zen: delete this;

AnswerRe: When to Define a Custom Exception Pin
#realJSOP14-Jan-11 1:35
professional#realJSOP14-Jan-11 1:35 
AnswerRe: When to Define a Custom Exception Pin
PIEBALDconsult14-Jan-11 2:05
mvePIEBALDconsult14-Jan-11 2:05 
AnswerRe: When to Define a Custom Exception Pin
Not Active14-Jan-11 2:36
mentorNot Active14-Jan-11 2:36 
GeneralRe: When to Define a Custom Exception Pin
#realJSOP14-Jan-11 2:53
professional#realJSOP14-Jan-11 2:53 
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
professional#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 
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 

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.