About Error handling in ASPX pages

  • Thread starter Thread starter Lau Lei Cheong
  • Start date Start date
L

Lau Lei Cheong

Hello,

I'm currently using Application_Error method in Global.asax.cs to handle
errors.

Recently, I heard about Page.ErrorPage and plan to use it for handling
errors on certain pages. Are there any major difference in using these
methods? My concern is mainly on the restrictions imposed on using these
method.

In my old error handling routine, I tried to use Server.GetLatError() to
get Exception object in the error page redirected by Response.Redirect() but
failed, can I use this method to retrieve the exception object in the new
page if Page.ErrorPage is used instead?

Thanks a lot.

Regards,
Lau Lei Cheong
 
In ASP.NET you use structured exception handling via Try..End Try
statements. These statements allow you to catch exceptions, handle
different exceptions differently and keep your application going.

Try
some code that may throw an exception
Catch ex as Exception
some code to handle the exception
the exception itself is accessible via the variable name given to
it on the "Catch" line, so we can find out what type of exception we
have:

ex.getType.ToString

we can get the exception message:

ex.message


End Try
 
You should also look into the
Microsoft.ApplicationBlocks.ExceptionManagement application block. It
provides some great functionality. Plus, they've already built and tested
it, so you don't have to.
 
True. However since the page is used to handle exceptions not on specific
task(such as when ASP.NET detects dangerous value in Request.Form[]) and
also unexpected server error, I think a general form of error handling would
be more appropiate.
 
Thanks for your information. This seems to be something interesting. :)

I'm learning how to build the interface through it.
 
I understand, but Page.ErrorPage isn't an error handler. It is just a
designation as to which page to show when there is an unhandled error.


Lau Lei Cheong said:
True. However since the page is used to handle exceptions not on specific
task(such as when ASP.NET detects dangerous value in Request.Form[]) and
also unexpected server error, I think a general form of error handling
would
be more appropiate.

Scott M. said:
In ASP.NET you use structured exception handling via Try..End Try
statements. These statements allow you to catch exceptions, handle
different exceptions differently and keep your application going.

Try
some code that may throw an exception
Catch ex as Exception
some code to handle the exception
the exception itself is accessible via the variable name given to
it on the "Catch" line, so we can find out what type of exception we
have:

ex.getType.ToString

we can get the exception message:

ex.message


End Try
 

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

Back
Top