|
-
Jan 11th, 2006, 08:54 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] Error handling Question
Hello,
When my project goes live I think it would be preferable to redirect users to a custom error page rather than the dot.net page with the stack trace on, how do I implement this with try catch blocks?
In the forms pages I can use response.redirect but how do I handle this when the error occurs in one of my classes?
-
Jan 11th, 2006, 01:13 PM
#2
Re: Error handling Question
This is implementable through the Web.Config file.
Try googling Web.Config run time error redirecting. Multiple methods exist to get this done and you should find some examples quickly that way.
Need to re-register ASP.NET?
C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i
(Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)
-
Jan 12th, 2006, 05:44 AM
#3
Re: Error handling Question
<customErrors defaultRedirect="defaulterrorpage.html"/>
-
Jan 12th, 2006, 12:09 PM
#4
Thread Starter
Frenzied Member
Re: Error handling Question
But if I put a try catch in will it still show as an error and redirect i.e the only reason I am really want ing to put to finally block in to ensure open data connection are closed if an error occurs?
-
Jan 12th, 2006, 12:40 PM
#5
Re: Error handling Question
If you catch an error, it does not bubble up to the error handler (you handled it) unless you re-throw it.
If you rethrow it, then all code before rethrowing it occurs, all code after does not.
Need to re-register ASP.NET?
C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i
(Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)
-
Jan 13th, 2006, 08:22 AM
#6
Thread Starter
Frenzied Member
Re: Error handling Question
Thats what I mean, I still need to show an error page when an error occurs but I also need to ensure data connections get closed? How to do both?
-
Jan 13th, 2006, 08:32 AM
#7
Re: Error handling Question
Add a Finally to your Try/Catch block and close the connection there.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Jan 13th, 2006, 08:43 AM
#8
Thread Starter
Frenzied Member
Re: Error handling Question
Thats what I have and that executes but then because the error has been handled (by the try catch finally) I cannot alert the user that an error occured i.e redirect to a custom errors page after.
-
Jan 13th, 2006, 08:58 AM
#9
Re: Error handling Question
You can ensure that your connections are closed within the Catch portion. After you've handled the error, do your checks, then rethrown some error (maybe a custom one) so that it redirects.
-
Jan 13th, 2006, 10:53 AM
#10
Thread Starter
Frenzied Member
Re: Error handling Question
I have this in the classes sup proc
VB Code:
Catch ex As System.Exception
If SqlCnnShippersCarriage.State = ConnectionState.Open Then
SqlCnnShippersCarriage.Close()
End If
Throw New ApplicationException("An Error occured in DespatchNewCarriage")
End Try
Then this in the web.config
VB Code:
<customErrors defaultRedirect="DefaultErrorPage.aspx"/>
This should work right?
-
Jan 13th, 2006, 11:26 AM
#11
Thread Starter
Frenzied Member
Re: Error handling Question
Tried testing it with this but its not working it's just showing the standard "Unhandled overflow exception error page when it hits the second throw rether than redirecting to my Customised page?
VB Code:
AddToSessionInserts()
Throw New OverflowException
Catch ex As System.Exception
If SqlCnnShippersCarriage.State = ConnectionState.Open Then
SqlCnnShippersCarriage.Close()
End If
Throw New OverflowException
End Try
-
Jan 13th, 2006, 11:26 AM
#12
Re: Error handling Question
-
Jan 13th, 2006, 11:51 AM
#13
Thread Starter
Frenzied Member
Re: Error handling Question
Yep even without the try catch stuff when I throw a completley unhandled exception it isnt using the custom errors redirect.
-
Jan 13th, 2006, 12:06 PM
#14
Thread Starter
Frenzied Member
Re: Error handling Question
Fixed thanks all,
Dumb ass me forgot to set Mode="On"
Code:
<customErrors mode="On" defaultRedirect="DefaultErrorPage.aspx"/>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|