try catch in global.asax file

I am maintaining some code created by a developer who has long since left the project. His documentation instructs not to place try catch blocks in the C# code,
becuase this is handled in the global asax file with a try statement. I politely disagree with
the approach. Look at the code below. It looks like it just performs cleanup after the application
ends.Plus no throw ever occurs, so the end user is not informed.




protected void Session_End(Object sender, EventArgs e)
{

   try
      {
      Custom.Project.Session.Delete(ConStr["Connection"].ToString(), Session.SessionID)
      }
   finally
   {
      Session.Abandon();
   }

}
LVL 2
brgdotnetcontractorAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
SriVaddadiConnect With a Mentor Commented:
Well,  I encountered similar coding pattern and I think people who worked with classic ASP does this. No offense. You could use Application_error and re-direct to an error page.  Though not sure u had any question.
0
 
brgdotnetcontractorAuthor Commented:
Hi SriVaddadi, I was pretty tired when I made this post and was not too imperative about emphasizing that I had a question. So here is my question.For the code I posted above, willl the code handlle any exception which will occur throughout the application? For example, suppose at runtime a null reference exception occurs.
0
 
SriVaddadiCommented:
Nope.
0
 
SriVaddadiCommented:
As i said earlier, Application_error or Session_Error are the events in global.asax where you could implement handler as it might be pain to implement exception handling all through the application
0
All Courses

From novice to tech pro — start learning today.