Standard Way of doing Exception Handling in 3-Tier or N-Tier Applications

There is a standard way to do exception handling in 3-Tier or N-Tier applications, which is applicable in any programming language (not specific to .Net or C# only), there are certain rules for Exception Handling. Refer to them below.

  • Exception should be logged into the database.

  • It should be logged on the origin location (from where it is caught).

  • Once an exception is caught:
     
    1. It should be wrapped into a Custom Exception class and then thrown further up the calling layers.

    2. Exception details should be logged into the database only once.

    3. If the exception is thrown from some other layer, then it should be forwarded to a further layer without logging to the database (since it's already logged in the origin).

    4. If it's a UI layer then a user friendly message should be displayed to the user.

For more clarity refer to the following screen:

Exception

X

Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now