Recently I attended Jeffrey Richter's training courses about .NET. He mentions one strategy of coding "Dying is awesome". That is, don't write "catch (Exception ex)" even at the root of program or event loop. If some exception thrown that is not handled, just let the process die.
I'm not sure this is right. Personally, I prefer to have a "try {...} catch(Exception ex) {log and try to recover}
" to wrap at the top level of execution. Actually, ASP.NET doesn't die if any exception is throw from asXx. If it does die for exception, then one silver-bullet request can silence the whole service.
What do you think?
I think it depends on what kind of app you are running and what the consequences of 'dying' are. For many client apps, dying is awesome. For servers, often not so much (and swallow-and-log is appropriate). There's no one-size-fits-all solution.
Also known as Offensive Programming.
You should check out, "Offensive Programming: Crash Early, Crash Often".
Which is a very different ideology from the norm of Defensive Programming:
[Defensive Programming] is intended to ensure the continuing function of a piece of software in spite of unforeseeable usage of said software.
I personally like the "Crash Early, Crash Often" philosophy.
I've seen far too many:
try
{
// ... Huge block of code goes here
}
catch(Exception ex)
{
// Do nothing...
}
Which is far worse than crashing hard. If exceptions are handled properly then a little defensive programming is fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With