Best Practice for Exception Handling in a Windows Forms Application?

前端 未结 16 2058
滥情空心
滥情空心 2020-11-29 14:20

I\'m currently in the process of writing my first Windows Forms application. I\'ve read a few C# books now so I\'ve got a relatively good understanding of what language feat

16条回答
  •  情话喂你
    2020-11-29 15:08

    When re-throwing an exception the key word throw by it self. This will throw the caught exception and still will be able to use stack trace to see where it came from.

    Try
    {
    int a = 10 / 0;
    }
    catch(exception e){
    //error logging
    throw;
    }
    

    doing this will cause the stack trace to end in the catch statement. (avoid this)

    catch(Exception e)
    // logging
    throw e;
    }
    

提交回复
热议问题