Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is "Dying is Awesome" preferred?

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?

like image 741
Morgan Cheng Avatar asked Feb 23 '09 04:02

Morgan Cheng


Video Answer


2 Answers

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.

like image 145
Brian Avatar answered Sep 24 '22 13:09

Brian


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.

like image 21
mmcdole Avatar answered Sep 20 '22 13:09

mmcdole