Best Practice for Exception Handling in a Windows Forms Application?

前端 未结 16 2067
滥情空心
滥情空心 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:18

    n my experience I've seen fit to catch exceptions when I know I'm going to be creating them. For instances when I'm in a web application and I'm doing a Response.Redirect, I know I'll be getting a System.ThreadAbortException. Since it's intentional I just have a catch for the specific type and just swallow it.

    try
    {
    /*Doing stuff that may cause an exception*/
    Response.Redirect("http:\\www.somewhereelse.com");
    }
    catch (ThreadAbortException tex){/*Ignore*/}
    catch (Exception ex){/*HandleException*/}
    

提交回复
热议问题