exceptionerror-handlingpresentation-layer

What is the suggested way to show exception messages on UI which were produced in Business Layer?


Is there a pattern OR 'a best practice' on creating user's friendly messages in the presentation layer by using exceptions which were thrown from the Business Layer?

Actually in many cases I prefer to throw Application Exceptions and this is forcing me to catch them on UI (aspx.cs pages). And if the process is complex which may produce many different types of exceptions I have to have many catch blocks to produce specific error messages.

Is there a better way coming to your mind? A pattern maybe for similar cases?

thanks


Solution

  • You could use a custom exception class to return errors via exception to the UI layer. These custom exceptions could then contain an error message that will be meaningful to the user, so you can display that just like you would any other error message.

    That way you will only need a single exception handler in the UI, instead of many for each type of error...