Jakub Šturc
Jakub Šturc

Reputation: 35767

What does the "on error goto 0" and "error resume next" in old ASP mean?

I am working with old ASP code and I am not sure about semantics of on error goto 0 and error resume next construction.

Can you recommend me some useful resources or enlight me directly?

Upvotes: 7

Views: 20376

Answers (4)

user3038458
user3038458

Reputation: 81

I used to use "single run" Do Loops to build classic ASP error handlers that covered multiple lines of code and multiple error cases. That technique relies on (compensates for?) the use of "On Error Resume Next" by breaking out of the loop as soon as an error occurs, then testing and reacting to classes of errors in some follow-on error handling code. Note that since the break occurs in a loop in the same function as the loop, you still have the context (variables) that were set when the loop was still executing, so your error handler should both use that context to log intelligent errors and clean up any lingering references as appropriate.

Check out the answer "Larry" provided to a similar question for a quick example of this.
How to handle errors in VB Script

Upvotes: 1

compcobalt
compcobalt

Reputation: 1362

on error resume next means just that ignore the error and resume next on error goto 0 means to end the on error resume next you can also do this

     <%
        on error resume next '<-- This code will resume and continue executing the code if there is an error



'YOUR CODE HERE

if err.number > 0 then  '<-- This code will look if there are any errors (even if resumed)
' or use If Err.Number <> 0 Then


        'DO SOMETHING IF ERROR
    %>
        Error Number <%= Err.Number %><BR>
        Error Description <%= Err.Description %><BR>        
        Source <%= Err.Source %><BR>

        LineNumber <%= Err.Line %><BR>

        <%end if%>

Upvotes: 3

Razzie
Razzie

Reputation: 31222

On error resume next: If there is an exception in the program, just ignore it and continue to the next statement. Considered very bad and ugly, and rightly so in my opinion. It's like having a big:

try
{
  // your code
}
catch
{
  // nothing! muhaha
}

in every method of your code (or worse, around the whole program).

On error goto 0: disables any error handler that is defined in the current procedure. It's like having a big try-catch around your code, which gets disabled as soon as its hit this line.

For more information, see the MSDN.

Upvotes: 5

Vikram
Vikram

Reputation: 6877

on error go to takes the execution code to a specific code book mark defined in the page.this is useful when you want to perform anything in case an error is encountered.

On error resume next moves on to the next code of execution after the erroneous code. Basically ignores the error and continues with the code. This is particulary useful when you are processing 100s of records and don't want the code to stop execution in case any record throws up error.

Upvotes: 3

Related Questions