Exception Handling in Global.asax

J

JP

I'm wondering if it's a good idea (or not) to include try-catch blocks in
the Global.asax handlers (specifically, Application_Start and
Session_Start).

So, does anyone know if I should include try-catch blocks in my Global.asax
handlers?
And, if so, what should I do with the caught exception (i.e., what do I do
in the catch block)?

Thanks.
 
M

Max

It's fine to use them anywhere, but you have to look at what happens if
something fails -- can your users continue on their marry way without that
bit of code running? In my app, there's no way, since I'm loading up some
important global and session variables. The user will have to be directed to
a page that says the site is down. This happens for example if the site
cannot connect to the database, or there is some invalid data in the user's
login credentials. If it's possible that some users can continue on while
others cannot, I might direct the faulty users to a "call support" page, but
then you really need to track down why that's happening -- if it's something
you can test for or fix in the app then do it! Leave try/catch as a last
resort.

Just know that try/catch should NEVER be used as part of your natural
business logic. Use them only for things like a faulty network connection to
your database, where you have no control of inside the application itself.

-Max
 
J

JP

Thank you, Max.


Max said:
It's fine to use them anywhere, but you have to look at what happens if
something fails -- can your users continue on their marry way without that
bit of code running? In my app, there's no way, since I'm loading up some
important global and session variables. The user will have to be directed to
a page that says the site is down. This happens for example if the site
cannot connect to the database, or there is some invalid data in the user's
login credentials. If it's possible that some users can continue on while
others cannot, I might direct the faulty users to a "call support" page, but
then you really need to track down why that's happening -- if it's something
you can test for or fix in the app then do it! Leave try/catch as a last
resort.

Just know that try/catch should NEVER be used as part of your natural
business logic. Use them only for things like a faulty network connection to
your database, where you have no control of inside the application itself.

-Max
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top