Hi, Needless to say: i'm new to ASP.NET and C#. In terms of error handling and custom error pages what i've been doing in my code is: 1) I wrote a custom error page named errors.aspx (is that original or what?) 2) Throughout my pages, those bits that seem to
be error prone I wrap them in try/catch blocks and then redirect the user to the errors.aspx page passing along a parameter with the error information (myexception.ToString()). 3) Then the errors.aspx shows a very "pretty" error message that includes the parameter
Ii sent and a list of environment variables that I think may help me when debugging; 4) I also indicated in the web.config that the default error message page is my errors.aspx That's my approach on how to avoid nasty error messages. Since i'm new to this
asp.net/c# stuff I'm guessing there are better ways to do it, so I would like to hear different views or ideas about it. Thanks, Carlos.
You don't need to wrap anything in try-catch; webconfig will execute your custom error page for you. As far as obtaining error information after the fact, I know it can be done, but I don't use custom error pages myself, so I'm not familiar with the process.
AutoFed
Rather than using redirect you can use response.transfer ( "errorpage.aspx"); In page_load event of errorpage.aspx, { Exception exp = Server.GetLastError(); Server.ClearError(); txtDisplay.Text = exp.Message; } this way you can display only message or even
can display the exception type specific error message by casting the exp variable. Happy programming
Ok now my 2 cents worth. 1. Only wrap code with Try Catch blocks if a) You need to execute a specfic action for a specfic Exception b) You need a Finally block c) You need to generalise your exceptions that you raise up your call stack by catching exception
and wrapping them in your own Exception type using InnerExceptions Do not use Try Catch to redirect to a "pretty" error page Use the element in web.config to have your users redirected to your pretty error page. This error page is indicated using the defaultRedirect
attribute of the customErros element. IMO the defaultRedirect page should be a simple html page. Making it an ASP.NET (aspx) handled page can lead to devs trying to do dangerous stuff when youa re already in a error state. During development you can turn Off
this redirecting to a pretty error page by using the mode attribute of the customErrors element If you need to log all unhandled errors do the logging in Application_Error in global.asax. Use the Exception Handler Application Block from Microsoft BTW response.
transfer does not exist it would be Server.Transfer HTH Pat
csantosnet
Member
10 Points
2 Posts
Error handling / custom error pages (best practices?)
Jul 14, 2003 12:32 PM|LINK
autofed
Participant
1789 Points
357 Posts
Re: Error handling / custom error pages (best practices?)
Jul 20, 2003 10:34 PM|LINK
yrskumar
Member
5 Points
1 Post
Re: Error handling / custom error pages (best practices?)
Jul 30, 2003 03:28 AM|LINK
dstruve
Star
9410 Points
1882 Posts
Re: Error handling / custom error pages (best practices?)
Jul 30, 2003 09:41 AM|LINK
DotNetNuke Houston
paddeo
Member
186 Points
47 Posts
Re: Error handling / custom error pages (best practices?)
Aug 01, 2003 10:02 AM|LINK