Is “Dying is Awesome” preferred?

后端 未结 16 777
栀梦
栀梦 2020-12-08 11:09

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)\" e

16条回答
  •  春和景丽
    2020-12-08 11:54

    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.

提交回复
热议问题