Exception Handling in .net web apps

后端 未结 6 741
盖世英雄少女心
盖世英雄少女心 2021-01-31 12:36

I admit it: I don\'t bother with too much exception handling. I know I should do more but I can never wrap my head around where to start and where to stop. I\'m not being lazy.

6条回答
  •  别那么骄傲
    2021-01-31 13:27

    I recommend you start by adding a good error page that catches all exceptions and prints a slightly less unfriendly message to the user. Be sure to log all details available of the exception and revise that. Let the user know that you have done this, and give him a link back to a page that will (probably) work.

    Now, use that log to detect where special exception handling should be put in place. Remember that there is no use in catching an exception unless you plan to do something with it. If you have the above page in place, there is no use in catching database exceptions individually on all db operations, unless you have some specific way to recover at that specific point.

    Remember: The only thing worse than not catching exceptions, is catching them and not doing nothing. This will only hide the real problems.

提交回复
热议问题