|
 |
asp_web_howto thread: On Error
Message #1 by rg1@h... on Mon, 23 Apr 2001 19:34:01
|
|
Hello.
In VBScript, I know there's an "On Error Resume Next". I need an "On Error
GoTo ErrorHandler". When I use "On Error GoTo ErrorHandler" I get a
compilation syntax error. Is there any way in VBScript that I can bypass
the rest of the code after encountering an error, and go directly to the
error handling routine?
TIA
Rita
Message #2 by "Alex Shiell, ITS, EC, SE" <alex.shiell@s...> on Tue, 24 Apr 2001 09:57:18 +0100
|
|
unfortunately not, thats all you've got!
in vbscript, you need to take this sort of approach:
on error resume next
...
some code
...
'put this line at strategic points were there may be an error
if err then call errorhandler()
...
some code
...
sub errorhandler()
Response.Clear
Response.write err.description
etc...
end sub
-----Original Message-----
From: rg1@h... [mailto:rg1@h...]
Sent: Monday, April 23, 2001 8:34 PM
To: ASP Web HowTo
Subject: [asp_web_howto] On Error
Hello.
In VBScript, I know there's an "On Error Resume Next". I need an "On Error
GoTo ErrorHandler". When I use "On Error GoTo ErrorHandler" I get a
compilation syntax error. Is there any way in VBScript that I can bypass
the rest of the code after encountering an error, and go directly to the
error handling routine?
TIA
Rita
________________________________________________________________________
Scottish Enterprise Network
http://www.scottish-enterprise.com
Message #3 by "Steve Schwarting" <steveschwarting@n...> on Tue, 24 Apr 2001 14:27:27
|
|
Unfortunately there is no on error goto errorhandler in asp. What I've
done in the past is just use the ON ERROR RESUME NEXT and then checked for
an error and called an error routine from there. I include the error
handling routine in every script via an #include so that I don't have to
think about what it does, just that errors will be handled in the same
fashion across the application. In my case, in the error routine I log
the error, and then redirect them to a "error encountered" page that
displays an error message. Hope that gives you some ideas for handling
error situations that you might be able to use.
...
On Error resume next
Set obj = Server.CreateObject("Blah.Blah")
If Err.Number <> 0 Then
Build_Error()
End If
...
-S.
> Hello.
>
> In VBScript, I know there's an "On Error Resume Next". I need an "On
Error
> GoTo ErrorHandler". When I use "On Error GoTo ErrorHandler" I get a
> compilation syntax error. Is there any way in VBScript that I can bypass
> the rest of the code after encountering an error, and go directly to the
> error handling routine?
>
> TIA
>
Message #4 by "Anthony Delcy" <DELCYAN@l...> on Tue, 24 Apr 2001 10:15:59 -0400
|
|
Hello,
Could someone explain why this phenomenon is happenning.
It seems that I cannot put the following line in an .inc file but the
same
logic works fine in an .html file.
See my code below.
Thank you
Anthony
<html>
<HEAD>
<title>NEW GTR NUMBER</title>=09
<SCRIPT language=3D"javascript"><!--function addNewOption(objSelect) {
var
optionNo =3D 0; optionNo +=3D 1; oNewOption =3D new Option(); oNewOption
.text =3D
"Option " + optionNo; objSelect.add(oNewOption, 1);}// --></SCRIPT>
</HEAD>
<body onload=3D"MainFunct()">
<LINK href=3D"GTR.css" rel=3Dstylesheet type=3Dtext/css>
<center>
<form name=3D"frmGTR" method=3D"post" action=3D"VerifyGTR()">
<table width=3D"600" height=3D"182">
<tr valign=3D"top" align=3D"left">
</tr>
</table>
<table bgcolor=3D"white" width=3D"400">
<tr>
<td>
<table class=3D"tbl" width=3D"457" cellpadding=3D"0"
cellspacing=3D"0" border=3D"1" bordercolor=3D"steelblue" rules=3D"none">
<tr bgcolor=3D"steelblue">
<th colspan=3D"3"
class=3D"tblhdr">GTR Details</th>
</tr>
<tr>
<td width=3D"5"></td>
<td NOWRAP><STRONG>Report
#</STRONG>
</td>
<td>
<input class=3D"editfld "
maxlength=3D"14" size=3D"30" id=3D"reportnumber" name=3D"reportnumber"
readOnly
style=3D"BORDER-LEFT-STYLE: none; BORDER-TOP-STYLE: none">
<INPUT class=3D"editfld "
id=3DDBCreatedby maxLength=3D14 name=3DDBCreatedby readOnly size=3D30
style=3D"BORDER-LEFT-STYLE: none; BORDER-TOP-STYLE: none; HEIGHT: 17px;
VISIBILITY: hidden; WIDTH: 55px">
</td>
</tr>
<tr>
<td></td>
<td NOWRAP><FONT
color=3Dfirebrick><STRONG>Title</STRONG></FONT></td>
<td>
<input class=3D"editfld "
maxlength=3D"40" size=3D"80" id=3D"title" name=3D"title" >
</td>
</tr>
<tr>
<td></td>
<td NOWRAP><STRONG>Product
#</STRONG> </td>
<td>
<input class=3D"editfld "
maxlength=3D"40" size=3D"80" id=3D"product" name=3D"product" >
</td>
</tr>
<tr>
<td></td>
<td NOWRAP><STRONG>TDPR #</STRONG>
</td>
<td>
<input class=3D"editfld "
maxlength=3D"40" size=3D"80" id=3D"tdpr" name=3D"tdpr" >
</td>
</tr>
<tr>
<td></td>
<td NOWRAP><STRONG>Project
#</STRONG> </td>
<td>
<input class=3D"editfld "
maxlength=3D"40" size=3D"80" id=3D"projectnumber" name=3D"projectnumber" >
</td>
</tr>
<tr>
<td></td>
<td NOWRAP><STRONG>Purpose</STRONG>
</td>
<td><TEXTAREA class=3Deditfld
cols=3D50
id=3Dpurpose name=3Dpurpose rows=3D3 style=3D"HEIGHT: 45px; WIDTH: 421px"
MAXLENGTH=3D"200"></TEXTAREA> =09
</td>
</tr>
<tr>
<td></td>
<td NOWRAP><STRONG>Change Control
#</STRONG> </td>
<td>
<input class=3D"editfld "
maxlength=3D"40" size=3D"80" id=3D"changecontrol" name=3D"changecontrol"
style=3D"HEIGHT: 19px; WIDTH: 422px">
</td>
</tr>
<tr>
<td></td>
<td NOWRAP><STRONG><FONT
color=3Dfirebrick>Section Code</FONT> </STRONG> </td>
<td>
<SELECT class=3D"editfld "
name=3D"sectioncode" style=3D"HEIGHT: 22px; WIDTH: 67px">
<OPTION value=3DD selected>
<OPTION value=3DD>D
<OPTION value=3DP>P
<OPTION value=3DS>S
<OPTION value=3DV>V
</OPTION>
</SELECT>
<input class=3D"butn" type=3D"submit" name=3D"Submit"
value=3D"Submit">
</td>
</tr>
</table>
</td>
</tr>
</table></TR></TABLE>
</form>
</center>
</body>
</html>
<script language=3D"VBscript">
=09
Sub MainFunct()
=09
if <%=3DRequest.Form("UserName") =3D "" or
Request.Form("Password") =3D ""%> then
window.location =3D "Redirect.asp"
else =09
document.all.DBCreatedby.value =3D
"<%=3DRequest.Form("UserName")%>"
end if
End sub
Sub VerifyGTR()
=09
if document.all.sectioncode.value =3D "" then
alert("You must select a Section Code from the
list")
else
frmGTR.action =3D "GTRInsert.asp"=09
end if
End sub=09
</script>
Message #5 by Rita Greenberg <rg1@h...> on Tue, 24 Apr 2001 07:33:16 -0700
|
|
Hi Steve.
Thanks for the great idea!
I implemented code similar to your idea and tested it using an invalid DSN
connection. I got the correct error message and was redirected to an error
page. Howeve, I also got another error message because I was trying to close
a record set that wasn't open. If the DSN connection had worked this would
have not been a problem!
Any thoughts on that?
Rita
-----Original Message-----
From: Steve Schwarting [mailto:steveschwarting@n...]
Sent: Tuesday, April 24, 2001 7:27 AM
To: ASP Web HowTo
Subject: [asp_web_howto] Re: On Error
Unfortunately there is no on error goto errorhandler in asp. What I've
done in the past is just use the ON ERROR RESUME NEXT and then checked for
an error and called an error routine from there. I include the error
handling routine in every script via an #include so that I don't have to
think about what it does, just that errors will be handled in the same
fashion across the application. In my case, in the error routine I log
the error, and then redirect them to a "error encountered" page that
displays an error message. Hope that gives you some ideas for handling
error situations that you might be able to use.
...
On Error resume next
Set obj = Server.CreateObject("Blah.Blah")
If Err.Number <> 0 Then
Build_Error()
End If
...
-S.
> Hello.
>
> In VBScript, I know there's an "On Error Resume Next". I need an "On
Error
> GoTo ErrorHandler". When I use "On Error GoTo ErrorHandler" I get a
> compilation syntax error. Is there any way in VBScript that I can bypass
> the rest of the code after encountering an error, and go directly to the
> error handling routine?
>
> TIA
>
Message #6 by Rita Greenberg <rg1@h...> on Tue, 24 Apr 2001 07:36:28 -0700
|
|
Thanks Alex. How disappointing!
-----Original Message-----
From: Alex Shiell, ITS, EC, SE [mailto:alex.shiell@s...]
Sent: Tuesday, April 24, 2001 1:57 AM
To: ASP Web HowTo
Subject: [asp_web_howto] RE: On Error
unfortunately not, thats all you've got!
in vbscript, you need to take this sort of approach:
on error resume next
...
some code
...
'put this line at strategic points were there may be an error
if err then call errorhandler()
...
some code
...
sub errorhandler()
Response.Clear
Response.write err.description
etc...
end sub
-----Original Message-----
From: rg1@h... [mailto:rg1@h...]
Sent: Monday, April 23, 2001 8:34 PM
To: ASP Web HowTo
Subject: [asp_web_howto] On Error
Hello.
In VBScript, I know there's an "On Error Resume Next". I need an "On Error
GoTo ErrorHandler". When I use "On Error GoTo ErrorHandler" I get a
compilation syntax error. Is there any way in VBScript that I can bypass
the rest of the code after encountering an error, and go directly to the
error handling routine?
TIA
Rita
________________________________________________________________________
Scottish Enterprise Network
http://www.scottish-enterprise.com
|
|
 |