using “on error resume next” in classic ASP, and how to handle errors

前端 未结 3 2105
清歌不尽
清歌不尽 2021-02-14 03:49

Good day all, I would like to ask a thing about on error resume next

let\'s assume we have a loop to navigate through a recordset like:

Do w         


        
相关标签:
3条回答
  • 2021-02-14 04:24

    on error resume next statement just only ignore the current line error and send the program control to the next line.

    on error goto 0 just stops the working of on error resume next.That's it.

    <%
    on error resume next
    response.write(1/0)
    if err.number <> 0 then
    response.write("<b>" & "err= "&"</b>")
    response.write(err.description)
    response.write("<b>" & " err number= "&"</b>" )
    response.write(err.number&"</br>")
    end if
    'after this statement ASP will no longer resume the error and program terminate at here if error occur after this line
    on error goto 0
    response.write(6/0)
    %>
    
    0 讨论(0)
  • 2021-02-14 04:41

    The correct code to use is

    Err.Clear
    

    I have tested it with the following code

    <%on error resume next
       response.write (p(10))
       Response.write(Err.Number)
       response.write("<br>")
       response.write(Err.description)
       response.write("<br>")
       Err.Clear
       Response.write(Err.Number)
       response.write("<br>")
       response.write(Err.description)
       response.write("<br>")
    
    
    
    %>
    

    And you can see the correct response is below, which shows the error being cleared

    *13

    Type mismatch

    0*

    0 讨论(0)
  • 2021-02-14 04:42

    VBScript resets the error on goto 0:

    on error resume next
    i = 1 / 0
    WScript.echo( err.number ) '' prints 11 (div by 0)
    on error goto 0
    WScript.echo( err.number ) '' prints 0 (no error)
    

    There is also the explicit err.clear().

    0 讨论(0)
提交回复
热议问题