Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post May 02, 2012 11:32 PM by asplearning
May 01, 2012 03:32 AM|LINK
Hello everyone, I am trying to implement error handler and I have one question to clarify. Right now I am using Try and Catch to catch error. When there is an error, I implemented logic to send email to the administrator. However, I am just wondering what
the client users will see on their client machines? Will the application send the email first and then redirect the users to default error page?
What I want is to send the email and then redirect. Will it work that way?
May 01, 2012 03:42 AM|LINK
The application will do what you tell it to do in the try catch. You have to put in the code that tells the application what to do inside the catch block.
May 01, 2012 03:49 AM|LINK
You are right hoopslife. What I did for the catch block is to send the email but as far as I know when error occurs, although no code to redirect to default error page in the catch block, the application still redirect to the error page. I specify the error
page in the web config file. So let get back to my question. Will it redirect after the code in the catch block execute?
May 01, 2012 04:28 AM|LINK
No, because you handled it with the try catch block. Just use Response.Redirect() to redirect to the page you want the user to see.
May 01, 2012 04:35 AM|LINK
Thanks hoopslife for the reply. If it doesn't redirect automatically, I just wonder in what cirumstances the default redirect error page is fired from the web config file. Is there a way that I can redirect automatically when there is an error without having
to write response.redirect in all catch blocks?
Thanks for your patience.
May 01, 2012 06:10 AM|LINK
Is there a way that I can redirect automatically when there is an error without having to write response.redirect in all catch blocks?
that will be taken care of your web.config setting...if you have that setting, then redirect will be done for all unhandled exceptions...
May 01, 2012 09:30 PM|LINK
Hello ramiramilu, I am confused here. I have configured the defaultredirect page in my web config file. According to the answer provided by the earlier posts, hoopslife seems to say that it doesn't redirect in the catch block. Did I misunderstand it?
My goal is to send an email to the adminstrator and then redirect when an error is caught. I am trying to figure out a way to redirect without having to insert the redirect code in every where of the catch blocks. Does it redirect after
the email is sent?
May 02, 2012 07:41 PM|LINK
If you catch the error you are then handling it yourself. So yes, you will need add redirect code in every try catch block. Since that code is redundant just create a method that you can call that will handle the redirect and the email for you.
May 02, 2012 07:51 PM|LINK
Only handle errors that you can do something about to recover from. Allow all other errors to bubble up the call stack. You can then handle these unexpected errors in a couple of ways.
You can add code to the Application_Error method of the global.asax file that maybe logs the error, sends an email and then redirects to a friendly page, or you could just ignore the error entirely and then it will hit the page defined in your web.config,
or you could use an error handling component like elmah or nlog to help you.
But the principle is always to only use try..catch where you expect an error and can do something about it, otherwise let it bubble up and handle it centrally.
May 02, 2012 11:32 PM|LINK
Thank you for all the replies. Now will just go for Elmah.