how to: handle exceptions, best practices

前端 未结 3 851
忘了有多久
忘了有多久 2021-02-11 00:54

need to implement a global error handling, so maybe you can help out with the following example...

i have this code:

public bool IsUserA         


        
3条回答
  •  梦毁少年i
    2021-02-11 01:54

    Your library code or the code that is used by higher-layers in your application must always only throw exceptions and never worry about how to deal with them.

    This is important because you may use this library at many places for different purposes.

    In your application presentation layer, if you're consuming a library code and you're aware about the possible exceptions then do catch them with try/catch.

    Since you're using asp.net I'd recommend to write a common page-base class and work some error handling mechanism in Page_Error event that catches all un-handled exceptions on the page.

    Even beyond that you can use Application_Error even in global.asax to catch any un-handled exception in any part of the application, Modules, Handler, services, pages etc.

    I'd strongly recommend to not make it a general practice to handle all exception in global Application_Error.

提交回复
热议问题