APGen Documentation Previous Topic: Default Error Handler Next Topic: Using Script.OnError Parent Topic: Error Handling    Error Handling
Script Language Error Handling
See Also:

Script language error handling is using a language-specific feature to handle run-time errors.  Script language error handling is the only form of error handling that allows recovery from run-time errors, and continued execution after the error occurs.

VBScript

To handle run-time errors in VBScript, use:

On Error Resume Next

To reset (disable) error handling in VBScript, use:

On Error Goto 0

When error handling is enabled in VBScript, use the VBScript Err object to determine if an error was raised.  See the VBScript documentation for more information on On Error Resume Next and the Err Object. 

An example of VBScript error handling:

<%#  Option Explicit

     Dim objFoo

     ' Enable error handling
     On Error Resume Next

     Set objFoo = Script.CreateObject("Foo")
     If Err.number <> 0 Then
          ' Object couldn't be created

          ' Log error
          Log.Write Err.Description, apgSeverityError, Err.Number
     Else
          ' Use objFoo somehow
          ...
     End If

     ' Reset error handling
     On Error Goto 0
#%>

When script error handling is used and an error occurs, APGen is not notified of the error, so it is not automatically logged.  The script is responsible for handling errors.  In this example, Log.Write() is called to log the error.

JScript

To handle run-time errors in JScript, use try ... catch for exception handling.  See the JScript documentation for more information on try and catch.

This JScript segment is equivalent to the VBScript segment just shown:

<%# @Language=JScript #%>
<%#  

     var objFoo;

     try
          {
          objFoo = Script.CreateObject("Foo");

          // Use objFoo somehow
          ...
          }
     catch (e)
          {
          // Log error
          Log.Write(e.description, apgSeverityError, e.number);
          }

#%>