Throwing exceptions and notifying the user

Recently I recently joined the asp.net mvc project, where there is not much consistency with eliminating exceptions in the controller; some developers return data to the client so that the user knows what is wrong, others throw it back so that they reach the server-level handler that processes and registers it, not letting the user know what is happening.

It seems obvious to me that both approaches are wrong on their own and need to be complemented by each other; I'm stuck on how to do this. I assume that the final exception handler / logger may redirect the user to the webpage with an error if something particularly unpleasant is caught, but this limits the mechanism to only serious things.

I’m kind of looking for a way to make a “throw” and “return ...” while I catch the exception, so I get it sorting and registering on the server side and getting the client side of the data, which allows me to tell the user that there is hiccups .

My experience with asp.net is very limited, and although I believe that I understand that mvc is enough to not be a problem, it’s kind of “what is the best practice?”. the question is from someone who works with people who are not worried about best practices.

+8
c # exception-handling
source share
2 answers

There is a good Elmah project for reporting errors and exceptions in ASP.NET applications. You can find here

ELMAH (error logging modules and error handlers) is an error logging application that is fully connected. It can be dynamically added to the running ASP.NET web application or even all ASP.NET web applications on the machine, without any recompilation or redeployment.

After ELMAH has been dumped into a running web application and properly configured, you get the following options without changing one line of your code:

  • Registration of almost all unhandled exceptions.
  • Remote webpage view the entire log of transcoded exceptions.
  • Remote viewing web page full details of any registered exception, including color stack traces.
  • In many cases, you can view the original yellow death screen generated by ASP.NET for this exception, even with customErrors mode disabled.
  • Email notification of each error at the time it occurs.
  • RSS feed of the last 15 errors from the journal.
+2
source share

The MVC application I'm working on implements Application_Error in Global.asax to handle exceptions thrown from the application, and then redirects the user to the standard error page. The error page controller processes the log and also displays enough error information to allow the support person to find their session in the system and help solve any problems.

0
source share

All Articles