Re: Problems Handling Errors Correctly
- From: Doug Semler <dougsemler@xxxxxxxxx>
- Date: Mon, 17 Sep 2007 07:19:26 -0700
On Sep 17, 12:04 am, "Jonathan Wood" <jw...@xxxxxxxxxxxxxxxx> wrote:
Yeah, the bottom line is that I don't particularly care for try...catch
exceptions. It gets to where you put try...catch in every routine if you
want to ensure you're program will never crash with an unhandled exception.
To me, exceptions are just that: "exceptional cases that should not
occur in normal usage" I treat them as "I fu*ked something up
somewhere". If I get an exception (unhandled or otherwise) I try to
fix the underlying CAUSE of the exception, whether it be due to
invalid arguments to a function or openning a nonexistent file. There
are some cases that I can think of that would have been more
convenient to return an error status than throw an exception (remoting
servers not available comes to mind <g>) back to me, but those are the
cases where I trap an exception in my code so that I can provide
graceful recovery/retry/feedback (a user isn't going to want to see
"SocketException" when trying to connect to a server when the network
is down...). General top level exception handlers are, to me, a bad
thing, because they tend to hide the underlying cause of problems from
the programmer.
You can still gracefully exit from unhandled exceptions: Add the
appropriate delegate to the AppDomain.CurrentDomain.UnhandledException
event and (for WinForms code) one to the Application.ThreadException
event. This way you can gracefully exit from/display/log any
exceptions that your code would not otherwise handle.
.
- Follow-Ups:
- Re: Problems Handling Errors Correctly
- From: Jonathan Wood
- Re: Problems Handling Errors Correctly
- References:
- Problems Handling Errors Correctly
- From: Jonathan Wood
- Re: Problems Handling Errors Correctly
- From: Peter Duniho
- Re: Problems Handling Errors Correctly
- From: Jonathan Wood
- Re: Problems Handling Errors Correctly
- From: Peter Duniho
- Re: Problems Handling Errors Correctly
- From: Jonathan Wood
- Re: Problems Handling Errors Correctly
- From: Peter Duniho
- Re: Problems Handling Errors Correctly
- From: Jonathan Wood
- Re: Problems Handling Errors Correctly
- From: Peter Duniho
- Re: Problems Handling Errors Correctly
- From: Jonathan Wood
- Re: Problems Handling Errors Correctly
- From: Peter Duniho
- Re: Problems Handling Errors Correctly
- From: Jonathan Wood
- Re: Problems Handling Errors Correctly
- From: Doug Semler
- Re: Problems Handling Errors Correctly
- From: Jonathan Wood
- Problems Handling Errors Correctly
- Prev by Date: Read Write Word Hyperlinks
- Next by Date: Re: doubt on abstration concept
- Previous by thread: Re: Problems Handling Errors Correctly
- Next by thread: Re: Problems Handling Errors Correctly
- Index(es):
Relevant Pages
|