Click here to Skip to main content
15,902,275 members
Home / Discussions / C#
   

C#

 
GeneralRe: Getting CurrentException without catch: use Marshal.GetExceptionCode() Pin
Paulo Zemek23-Nov-09 13:12
Paulo Zemek23-Nov-09 13:12 
QuestionParameterless catch? Pin
Etienne_12323-Nov-09 0:20
Etienne_12323-Nov-09 0:20 
AnswerRe: Parameterless catch? PinPopular
dojohansen23-Nov-09 0:23
dojohansen23-Nov-09 0:23 
AnswerRe: Parameterless catch? Pin
Richard MacCutchan23-Nov-09 0:24
mveRichard MacCutchan23-Nov-09 0:24 
GeneralRe: Parameterless catch? Pin
Etienne_12323-Nov-09 0:29
Etienne_12323-Nov-09 0:29 
GeneralRe: Parameterless catch? Pin
dan!sh 23-Nov-09 0:35
professional dan!sh 23-Nov-09 0:35 
GeneralRe: Parameterless catch? Pin
dojohansen23-Nov-09 1:03
dojohansen23-Nov-09 1:03 
GeneralRe: Parameterless catch? Pin
Luc Pattyn23-Nov-09 1:10
sitebuilderLuc Pattyn23-Nov-09 1:10 
Etienne_123 wrote:
To prevent my system from crashing when an error does occur


Most often that does not make sense at all.
An exception indicates something went wrong, you can not just ignore it, you should:
1) probably log it
2) act on it (if nothing else, throw it again, so a higher level of the code can act on it).
3) consider informing the user.

And you should only catch the exceptions you can handle in a meaningful way, hence catch them as specific as possible.

Examples:
- when writing to a file, if it fails (error in path, disk full, whatever IOException) you can't ignore that, since then your output would be uncertain; here you must inform the user, unless you have a retry that succeeds.
- when parsing user input, a parse exception has to be reported to the user so he can re-enter data.

The rare exception to the rule is e.g. where you have a retry loop, then all exceptions except for the one in the last retry iteration can be left unhandled and unreported (I suggest to include a comment as to why a catch block is empty then); the exception in the last retry iteration has to be handled though, since that is the exit result of the retry loop.

Smile | :)

Luc Pattyn [Forum Guidelines] [My Articles]

I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


GeneralRe: Parameterless catch? Pin
Richard MacCutchan23-Nov-09 2:04
mveRichard MacCutchan23-Nov-09 2:04 
GeneralRe: Parameterless catch? Pin
Eddy Vluggen23-Nov-09 2:21
professionalEddy Vluggen23-Nov-09 2:21 
GeneralRe: Parameterless catch? Pin
Saksida Bojan23-Nov-09 6:15
Saksida Bojan23-Nov-09 6:15 
GeneralRe: Parameterless catch? Pin
Eddy Vluggen23-Nov-09 7:46
professionalEddy Vluggen23-Nov-09 7:46 
GeneralRe: Parameterless catch? Pin
OriginalGriff23-Nov-09 4:13
mveOriginalGriff23-Nov-09 4:13 
GeneralRe: Parameterless catch? Pin
Luc Pattyn23-Nov-09 10:10
sitebuilderLuc Pattyn23-Nov-09 10:10 
AnswerRe: Parameterless catch? Pin
Shameel23-Nov-09 2:05
professionalShameel23-Nov-09 2:05 
AnswerRe: Parameterless catch? Pin
Christian Graus23-Nov-09 2:21
protectorChristian Graus23-Nov-09 2:21 
GeneralRe: Parameterless catch? Pin
Richard MacCutchan23-Nov-09 3:12
mveRichard MacCutchan23-Nov-09 3:12 
GeneralRe: Parameterless catch? Pin
Etienne_12323-Nov-09 3:51
Etienne_12323-Nov-09 3:51 
GeneralRe: Parameterless catch? Pin
Richard MacCutchan23-Nov-09 4:25
mveRichard MacCutchan23-Nov-09 4:25 
GeneralRe: Parameterless catch? Pin
Luc Pattyn23-Nov-09 10:14
sitebuilderLuc Pattyn23-Nov-09 10:14 
QuestionUSB to Parallel Pin
Darren Shields23-Nov-09 0:03
Darren Shields23-Nov-09 0:03 
AnswerRe: USB to Parallel Pin
Natza Mitzi23-Nov-09 2:05
Natza Mitzi23-Nov-09 2:05 
AnswerRe: USB to Parallel Pin
The Man from U.N.C.L.E.23-Nov-09 2:41
The Man from U.N.C.L.E.23-Nov-09 2:41 
QuestionUsing Function Keys Pin
khosnur22-Nov-09 21:55
khosnur22-Nov-09 21:55 
AnswerRe: Using Function Keys Pin
Nagy Vilmos22-Nov-09 21:59
professionalNagy Vilmos22-Nov-09 21:59 

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.