|
Error Trapping #1 by Charles Carroll
Now we will demonstrate how to trap VBScript
errors that occur in your scripts with code. The script below runs without incident. All the syntax
in the script is correct.
filename=/learn/test/errordivide1.asp
<TITLE>errordivide1.asp</TITLE>
<body bgcolor="#FFFFFF">
<%
' ASP program that works if numbers are legit
x=7
y=2
z=x/y
response.write z & "<br>"
%>
</body></html>
Now even though all the syntax in the script
is correct, since one of the numbers has the effect of creating a "division by
zero" error the script fails.
filename=/learn/test/errordivide2.asp
<TITLE>errordivide2.asp</TITLE>
<body bgcolor="#FFFFFF">
<%
' ASP program that works if numbers are legit
x=7
y=2 ' if changed to 0 this will crash
z=x/y
response.write z & "<br>"
%>
</body></html>
Now we use the VBScript error trapping to
present a message instead of a catastrophic script error.
filename=/learn/test/errordivide3.asp
<TITLE>errordivide3.asp</TITLE>
<body bgcolor="#FFFFFF">
<%
' ASP program that works if numbers are legit
on error resume next
x=7
y=0
z=x/y
response.write z & "<br>"
If err.number=0 then
response.end
end if
pad=" "
response.write "<b>VBScript Errors Occured!<br>"
response.write parm_msg & "</b><br>"
response.write pad & "Error Number= #<b>" & err.number & "</b><br>"
response.write pad & "Error Desc.= <b>" & err.description & "</b><br>"
response.write pad & "Help Context= <b>" & err.HelpContext & "</b><br>"
response.write pad & "Help File Path=<b>" & err.helpfile & "</b><br>"
response.write pad & "Error Source= <b>" & err.source & "</b><br><hr>"
%>
</body></html>
 |  |  |
 |
There are many worthy charities!!. But perhaps help starving children in Africa or South America AND help Charles too.
a $5 tip buys him lunch at McDonalds,
a $20 tip buys his kid Hitoshi a new computer game,
a $39 tip buys his daughter Michiko a few nice outfits.
See our donor list.
|  |
 |  |  |
|
|
|
|