Click here to Skip to main content
15,904,822 members
Home / Discussions / C#
   

C#

 
GeneralRe: Exceptions Pin
Luc Pattyn8-Jan-09 10:28
sitebuilderLuc Pattyn8-Jan-09 10:28 
GeneralRe: Exceptions Pin
Jason C Bourne8-Jan-09 10:31
Jason C Bourne8-Jan-09 10:31 
GeneralRe: Exceptions Pin
CodingYoshi8-Jan-09 10:57
CodingYoshi8-Jan-09 10:57 
GeneralRe: Exceptions Pin
Colin Angus Mackay8-Jan-09 11:18
Colin Angus Mackay8-Jan-09 11:18 
GeneralRe: Exceptions Pin
Jason C Bourne8-Jan-09 11:21
Jason C Bourne8-Jan-09 11:21 
GeneralRe: Exceptions Pin
Colin Angus Mackay8-Jan-09 10:41
Colin Angus Mackay8-Jan-09 10:41 
AnswerRe: Exceptions Pin
HosamAly8-Jan-09 10:37
HosamAly8-Jan-09 10:37 
AnswerRe: Exceptions Pin
Colin Angus Mackay8-Jan-09 10:37
Colin Angus Mackay8-Jan-09 10:37 
CodingYoshi wrote:
create my own custom exception


Yes.


CodingYoshi wrote:
simply create a new Exception object


Never create an Exception object. Only something derived from Exception.


CodingYoshi wrote:
create a new Exception object and add my own message to it and link the inner exception to it.


Where is this other Exception object coming from that you are putting in the inner exception? it isn't in the code you showed.

Basically, create a custom exception class or use an existing specific exception if one exists. For example, I'll often create a DalException, or an excption for a specific part of the model in my application, e.g. a SalesException or BookingException. I won't create one for absolutely every exentuality, but I use them in logical groupings.


CodingYoshi wrote:
Or should I throw ApplicationException?


I'm not a fan of the ApplicationException, it is too generic. You can derive from it if you want.

In terms of how much code to put in your try block, that depends on the individual situation.

If the two exceptions are distinct, as in your example, then I don't really see a problem with the first way you showed it. (i.e one try block.)

I would suggest that if the two method calls can potentially produce the same kind of exception and you need to differenciate which method call produced the exception then your second example would be best.

* Developer Day Scotland 2 - Free community conference
* The Blog of Colin Angus Mackay


Vogon Building and Loan advise that your planet is at risk if you do not keep up repayments on any mortgage secured upon it. Please remember that the force of gravity can go up as well as down.

QuestionDefaultValue() attribute problem Pin
xJorDyx8-Jan-09 8:48
xJorDyx8-Jan-09 8:48 
AnswerRe: DefaultValue() attribute problem Pin
DaveyM698-Jan-09 8:58
professionalDaveyM698-Jan-09 8:58 
GeneralRe: DefaultValue() attribute problem Pin
xJorDyx8-Jan-09 9:49
xJorDyx8-Jan-09 9:49 
GeneralRe: DefaultValue() attribute problem Pin
DaveyM698-Jan-09 13:01
professionalDaveyM698-Jan-09 13:01 
AnswerRe: DefaultValue() attribute problem Pin
Wendelius8-Jan-09 10:01
mentorWendelius8-Jan-09 10:01 
QuestionGood tutorials Pin
damennix8-Jan-09 8:17
damennix8-Jan-09 8:17 
AnswerRe: Good tutorials Pin
Mohammad Dayyan8-Jan-09 9:36
Mohammad Dayyan8-Jan-09 9:36 
AnswerRe: Good tutorials Pin
Dragonfly_Lee8-Jan-09 17:35
Dragonfly_Lee8-Jan-09 17:35 
QuestionGood tutorials Pin
damennix8-Jan-09 8:17
damennix8-Jan-09 8:17 
GeneralRe: Good tutorials Pin
Luc Pattyn8-Jan-09 8:29
sitebuilderLuc Pattyn8-Jan-09 8:29 
QuestionCall Method Multuple Times Pin
RadioButton8-Jan-09 6:59
RadioButton8-Jan-09 6:59 
AnswerRe: Call Method Multuple Times Pin
Giorgi Dalakishvili8-Jan-09 7:02
mentorGiorgi Dalakishvili8-Jan-09 7:02 
GeneralRe: Call Method Multuple Times Pin
Luc Pattyn8-Jan-09 7:03
sitebuilderLuc Pattyn8-Jan-09 7:03 
QuestionRe: Call Method Multuple Times Pin
Eddy Vluggen8-Jan-09 7:13
professionalEddy Vluggen8-Jan-09 7:13 
GeneralRe: Call Method Multuple Times Pin
Jon Rista8-Jan-09 7:38
Jon Rista8-Jan-09 7:38 
AnswerRe: Call Method Multuple Times [modified] (improved code) Pin
Dan Neely8-Jan-09 8:28
Dan Neely8-Jan-09 8:28 
JokeRe: Call Method Multuple Times Pin
DaveyM698-Jan-09 8:40
professionalDaveyM698-Jan-09 8:40 

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.