|
Application_Error exists in Global.asax.
Most of the unhandled exception are caught here.
While testing, I changed the name of a stored procedure to something that doesn't exist in the database.
Now the control does not come to Application_Error.
When I debug the app, the debugger shows exception when ExecuteReader is called.
I do not have any try...catch
I believe all exceptions must be caught by Application_Error.
But it does not behave so.
|
|
|
|
|
Can you share few information?
1. What code is present in your Application_Error? If you remove everything in it and place debugger, does it hit the method?
2. IIS7? CustomError mode in Web.config?
3. Are other methods of Global.asax getting triggered, like Session_start?
4. Is there any other .config file in your application?
|
|
|
|
|
My Application_Error contains 3 lines - Server.GetLastError , Server.Transfer and Server.ClearError .
I tried removing all these lines and simply put a return statement on a breakpoint, but it did not hit.
My development environment is IIS 5.1, Windows XP, Visual Studio 2010.
I tried both with customError mode="Off" and customError mode="On" with the same results.
Session_Start is being called in Global.asax and I checked it by placing a breakpoint.
I only have a web.config file.
I created another sample file and tried it with the same results.
I have shared the sample for you if you have the time.
https://docs.google.com/file/d/0BwxeXZOAvlxJa3AxMUIxVkVUSEk/edit?usp=sharing[^]
You can download it by selecting File -> Download.
Since I'm not a web developer, my current solution is to place a try...catch and then redirect to the error page from the catch handler.
This works for me.
Any help would be appreciated.
Thanks for your time.
|
|
|
|
|
Hi Santosh,
I downloaded it and opened in my VS2010 as a website. Set the break points in Global.sax. Built and ran.
Guess what? It hit the Application_Error method.
Am I missing something or you are?
Please re-run the application that you shared with me with breakpoints and see again.
|
|
|
|
|
I'm definitely missing something.
It still gave me the same behavior.
So to make sure, I used Windows 8 and Visual Studio 2012.
I created a new application and it still gave me the same behavior.
It hit Session_Start , but did not hit Application_Error .
While debugging the error is shown in Default.aspx.cs and it says SqlException was unhandled by user code and Could not find stored procedure 'StoredProcedure2'.
If I use a try...catch and re-throw the exception from the catch handler, it hits Application_Error .
Anyway, thanks for your time.
|
|
|
|
|
I suspected some configuration issue here because the machines were used a lot before and so installed a fresh copy of Windows 8 and Visual Studio 2012.
Now I'm able to get it to work.
Thanks for your time.
However, I have one question.
Why is the debugger showing an exception in the .cs file before hitting Application_Error ?
Application_Error is hit only when F5 is pressed again after the exception is shown.
The exception can be see here - https://docs.google.com/file/d/0BwxeXZOAvlxJc28teld2R1BkVEk/edit?usp=sharing[^]
|
|
|
|
|
Now, since you share further steps, try to disable all code exceptions in VS:
Do Cntrl+Alt+E in Visual Studio and then uncheck all - Application_Error should get hit. I guess it does not work otherwise.
Worth a shot?
|
|
|
|
|
Thanks Sandeep,
It worked perfectly.
|
|
|
|
|
«_Superman_» wrote: It worked perfectly.
Awesome!
Glad I could help you out.
|
|
|
|