Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Application_Error in global.asax really the way to handle errors? [closed]

Tags:

c#

asp.net

The other day I appeared in interview, the interviewer asked me what is the purpose of global.asax. I said it is for catching specific events like Session_Start etc. He then said how do you do exception handling in your code? I said we wrap the statements in try catch block. He then said would you do this for all button click events in your code? That is so tedious and repetitive. Where does OOP come into picture here? He said you should always catch errors in Application_Error in global.asax. I said OOP does not say that you should catch all errors in this event. We should always catch specific exceptions and that should be in those respective handlers. We fell in quite a quarrel during interview and I straightforward said on his face that I do not agree with you.

Can you tell me how do you all handle exceptions on server side?

Thanks in advance :)

like image 445
TCM Avatar asked May 16 '11 15:05

TCM


People also ask

Which is the best way to handle errors in net?

You can handle default errors at the application level either by modifying your application's configuration or by adding an Application_Error handler in the Global. asax file of your application. You can handle default errors and HTTP errors by adding a customErrors section to the Web. config file.

Which of the following is the easiest way to track all unhandled errors?

Retrace can automatically collect all . NET exceptions that are occurring within your application with no code changes. This includes unhandled exceptions but can also include all thrown exceptions or first chance exceptions. The best thing about this is it works with all types of ASP.NET applications.

How does MVC handle application error in global asax?

Setting HandleError Attribute as a Global Filter Any unhandled exception that takes place within the boundary of the MVC application will now be handled by this global error handler. To test this global handler, comment out the [HandleError] attribute from the action or the controller and then run the application.

What is error write the technique for handling error?

Error handling helps in handling both hardware and software errors gracefully and helps execution to resume when interrupted. When it comes to error handling in software, either the programmer develops the necessary codes to handle errors or makes use of software tools to handle the errors.


1 Answers

The short answer I have found is you code the way that you are instructed to code even when you disagree with it if you want to keep the job.

However if you only catch the errors in the Global.asax then you lose out on local variable debugging, and graceful error handling. Errors handled in the Global.asax generally do not fail gracefully.

I do generally catch any unhandled errors in the Global.asax but to me only handling this here is like not having brakes on the car because it has airbags. (Yes i love Metaphors)

like image 86
Chad Avatar answered Nov 03 '22 07:11

Chad