Catch-all error handling on application level?

前端 未结 5 1876
面向向阳花
面向向阳花 2021-01-19 04:58

I have a WPF form with a couple of buttons, and for each button I have error handling code:

try {bla bla} 
catch(Exception e){
  more bla
}

5条回答
  •  礼貌的吻别
    2021-01-19 05:11

    If it is a WinForms app, you can encapsulate the Application.Run() call in a try catch statement, although I really wouldn't recommend this, you should only be using try catches where they are absoloutely needed and deal with exceptions whereever possible before just relying on catches.

    I know this method works though as I had to use it temporarily once to do some cleaning up on the crashing of an application.

提交回复
热议问题