Where to put try catch

前端 未结 11 640
一整个雨季
一整个雨季 2020-12-09 03:51

Consider this scenario: I have 3-layer app, when the user click on the button the button event handler calls a method in biz layer that do whatever with data my button even

11条回答
  •  醉梦人生
    2020-12-09 04:54

    You only want to use try catches to manage unhandled code. An example is I have a COM object I am communicating with and I don't want it to stay open and create a memory leak. The other acceptable alternative is to catch errors on events in your database before allowing the exception to continue.

    You do not ever want to use try catches to handle situations where you are unsure you code will work and want a backup plan.

    So where does that leave you when apps blow up, use custom error pages to indicate a problem has occurred in your web apps and for thick clients parse code off into worker threads so they don't blow up your main thread if they fail. Good luck!

提交回复
热议问题