1

I was wondering if there was a way to catch all unhandled exceptions in a visual studio project. My project does not have any files named global or global.asax so I was wondering if there was some other way to catch any and all unhandled exceptions? So far I've tried to put exception handling around specific blocks of code, but it doesn't have any effect.

jsmith
  • 565
  • 3
  • 14
  • 28
  • 1
    If your project doesn't have one.. you can add the file by right clicking on your project in solution window..Using Global.asax is more elegant than using catch blocks all over the code behind... – Flowerking Mar 21 '12 at 14:43
  • "So far I've tried to put exception handling around specific blocks of code, but it doesn't have any effect" ... can you post some examples of how you've attempted to handle the exceptions and explain what you mean? Have you tried adding a global.asax file putting some code in the void Application_Error(object sender, EventArgs e) event? –  Mar 21 '12 at 14:46

3 Answers3

3

You can add a global.asax file to your website and add an implementation for Application_Error and all exceptions that are thrown during processing a request will make their way there. After handling the exception, call Server.ClearError() to prevent the default ASP.NET error page from showing up.

Another alternative is to install ELMAH in your project, which is a very nice and very customizable error handling framework.

csm8118
  • 1,213
  • 9
  • 11
2

simply add global.asax, add new item and choose "Global Application Class"

enter image description here

Antonio Bakula
  • 20,445
  • 6
  • 75
  • 102
0

I mentioned here about both Page/Application Level handling

Community
  • 1
  • 1
Pankaj
  • 9,749
  • 32
  • 139
  • 283