View Full Version : On Error, Redirect to a new page.
I'm trying to detect if an error occurs, redirect them to a new page. How do I detect if theres an error?
victoria_1018
11-07-2002, 01:27 AM
You can try using the code below,
<B>On Error Resume Next</B>
Place this code in your program and test for error, test this code in different parts of your program and see where the error occur.
Regards
whammy
11-07-2002, 01:32 AM
Be very very very careful using "On Error Resume Next". Actually I would recommend against it unless you are aware of ALL of the ramifications.
First of all you should test your applications thoroughly, and fix any errors you run into...
...but if you do use "On Error Resume Next", make sure that if an error occurs (especially a database error), you at least log the error (and any/all querystrings or post data that the user has entered) to a text file, so you can enter the data yourself (preferably save everything to a .csv or .txt file so you can import it later!).
I have a strange sense of dejavu... seems like I've already typed this nearly word for word (not to mention this exact subject was brought up in a company meeting today!) ;)
If you're going to use "On Error Resume Next" make sure you capture EVERYTHING that the user has entered and save the information they HAVE entered. That way you can adjust their database record accordingly later, or you are going to have some ticked off users (and clients - which is not good!).
As for how to use it... just do a search on http://www.google.com ... I'm sure you'll find plenty of relevant answers, I almost always do.
;)
BigDaddy
11-07-2002, 02:15 AM
The major problem with using on error..resume next is if you execute it within a loop. If you get an error, it keeps on looping, and getting more errors, etc....etc....etc....
It can quickly hose a server pretty badly.
Not unlike forgetting to put "RS.movenext" prior to "loop".
:D
whammy
11-07-2002, 02:47 AM
Heh... that's a good point too, which is a huge oversight on my part that I probably should have noted - but I tend to try to fix errors instead of ignore them.
Using anything in a loop that isn't working correctly (or even if it is, uses up too many resources) will probably crash just about anything - or at the least make it run REALLY SLOW.
I think BigDaddy can relate with that, with some of the experiments I've done. :)
I am aware of this, but I don't want that. I am working on an application that will have errors. If the page has errors, I want it to redirect the user to a coming soon page, unless the user has my IP address. I have the IP address part figured out, but not the redirecting on errors.
BigDaddy
11-07-2002, 03:26 AM
I like that idea. Assuming the IP won't change, that's pretty cool.
I am aware of all the problems On Error Resume Next can do, the script I am coding isn't complete, I'm still testing it. But I have let users come see it, just to see what it will be. I will do some reserch on Google and post back if I have any more questions.
oracleguy
11-07-2002, 05:39 AM
Originally posted by BigDaddy
Not unlike forgetting to put "RS.movenext" prior to "loop".
:D :D I've done that once or twice.
I see what your saying you want something like this?
<%
On Error Goto err_Handler
...Your Code...
err_Handler:
Response.Redirect "comingsoon.asp"
%>
You also can access the error number and/or description using the 'err' object.
Mhtml
11-07-2002, 08:27 AM
Hey, I always wonderd if you could do something like you have there oracle...
[quote]
<%
On Error Goto err_Handler
...Your Code...
err_Handler:
Response.Redirect "comingsoon.asp"
%>
[/code]
I remeber that from Qbasic, back when I was 9 or so. My common one was goto loop for my little games which required animation.
Yes that seems to be what I want.
I'll try that out.
I remeber that from Qbasic, back when I was 9 or so.
I started Web-Design when I was 10, I'm 12 right now :)
whammy
11-08-2002, 12:19 AM
Originally posted by BigDaddy
Not unlike forgetting to put "RS.movenext" prior to "loop".
Yeah, I've done that once or twice myself. Only to hear another developer say "Who is killing the *(&^(*&*^^& server?"
;)
rcreyes
11-08-2002, 03:07 AM
Just to add a few comments about the ON ERROR statement gotchas:
The ON ERROR statement is valid until another ON ERROR statament is encountered, for example if Function A contains an On Error statement, and function A calls Function B, but function B does not have an ON ERROR statement, the ON ERROR statement from function A is still valid, meaning if an error occurs in Function B, it is the ON ERROR statement from Function A that will handle error, in other word, if an error is encountered in Function B, the program flow will immediately jump to the line of code followed the call to Function B in Function A.
Thanks,
Ray
Roy Sinclair
11-08-2002, 07:17 PM
Another important addition to the ON ERROR usage, if you have a case where you want to trap errors only for a specific line you can do something like this:
on error resume next
' statement with possible error goes here
if err.number <> 0 then
' error handling code goes here
end if
on error goto 0 ' Resumes normal error handling
Specifically on error goto 0 is the default setting for error handling.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.