The following code has run-time error on "divide by 0" error. I expect
"do the work<br>" will not print in the browser, since it happen after
the code
that cause the error. However, this is the output: any ideas why?? Or
this is the nature of ASP scripting language that is being executed in
sequential order? Please advice. thanks!!

//////// output ///////////////////////////

before error
do the work
Division by zero
after error handling

/////////// code ///////////////////////////
<%
On Error Resume Next
Response.write "before error<br>"
dblValue = 1/aa '== Will cause a divide by 0 error

Response.Write "do the work<br>"

If Err.Number <> 0 Then
Response.write Err.Description & "<br>"
End If

Response.Write "after error handling<br>"
%>

////////////////////////////////////////////

Re: ASP will still execute code after run-time error has detected? by Mike

Mike
Thu Jul 13 02:10:12 CDT 2006


John wrote:
> The following code has run-time error on "divide by 0" error. I expect
> "do the work<br>" will not print in the browser, since it happen after
> the code
> that cause the error. However, this is the output: any ideas why?? Or
> this is the nature of ASP scripting language that is being executed in
> sequential order? Please advice. thanks!!
>
> //////// output ///////////////////////////
>
> before error
> do the work
> Division by zero
> after error handling
>
> /////////// code ///////////////////////////
> <%
> On Error Resume Next
> Response.write "before error<br>"
> dblValue = 1/aa '== Will cause a divide by 0 error
>
> Response.Write "do the work<br>"
>
> If Err.Number <> 0 Then
> Response.write Err.Description & "<br>"
> End If
>
> Response.Write "after error handling<br>"
> %>
>
> ////////////////////////////////////////////

'On Error Resume Next' tells the compiler to ignore any runtime errors
and resume with the next line of code. Details of the (last) error are
stored in the Err Object. Without 'On Error Resume Next', the compiler
would halt processing this script at the point it encounters a divide
by zero error (or indeed any runtime error).

--
Mike Brind