Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happens if an unhandled exception is thrown in Application_Start?

... will the Application_Start method be ran again for the next request(s) or not?

Does it depend on ASP.NET version, hosting server version and/or other context?

I am trying to determine if it's a good thing to load critical assemblies there or not. For example data access assemblies which are vital to the functioning of the whole application or not. Failure to load such assembly would make subsequent requests useless.

like image 964
Andrei Rînea Avatar asked May 03 '11 23:05

Andrei Rînea


People also ask

What happens if there is an unhandled exception?

An unhandled exception occurs when the application code does not properly handle exceptions. For example, When you try to open a file on disk, it is a common problem for the file to not exist. The . NET Framework will then throw a FileNotFoundException.

How does unhandled exception handle in .NET core?

ASP.NET Core Error Handling You can register it as a global filter, and it will function as a global exception handler. Another option is to use a custom middleware designed to do nothing but catch unhandled exceptions. You must also register your filter as part of the Startup code.

When an unhandled exception arises in an ASP.NET application?

Summary. When an unhandled exception occurs in an ASP.NET web application the ASP.NET runtime raises the Error event and displays the configured error page. We can notify the developer of the error, log its details, or process it in some other fashion, by creating an event handler for the Error event.

How do you handle an unhandled exception in the thread?

Uncaught exception handler will be used to demonstrate the use of exception with thread. It is a specific interface provided by Java to handle exception in the thread run method. There are two methods to create a thread: Extend the thread Class (java.


1 Answers

Application_Start will be fired only once for each web application so in your case, the start will not happen again for subsequent requests.

Typically, I prefer to put one time start-up code in the application start within try-catch and if there is an exception then set the global error flag. In each BeginRequest, the flag is checked and if it is set, user is redirected to a custom error page indicating the site is down and please contact the administrator.

like image 79
VinayC Avatar answered Nov 16 '22 01:11

VinayC