|
APGen Object Reference |
|
See Also: |
The APGError object contains information about errors that may have occurred in an APG script.
| oError | An APGError object. |
| Number | Integer | Returns the COM error code. |
| Description | String | Returns the error description. |
| Severity | ApgLogSeverityEnum | Returns the severity of the error. |
| FilePath | String | Returns the path of the file where the error occurred. |
| LineNumber | Integer | Returns the file line number where the error ocurred. |
| Source | String | Returns a string describing the object that raised the error. |
| Handled | Boolean | Sets/returns whether the error has been completely handled by an error handler. |
| Script | APGScript object | Returns the APGScript where the error occurred. |
| Clear() | Clears the APGError object of any error information. |
APGError objects are obtained using APGScript.GetLastError(), and they are passed to Script.OnError handlers and Script Error event handlers.
This example runs an APG script, and uses APGScript.GetLastError() to check if any errors occurred.
Note that error handling with Script.OnError and Script Error event handlers is usually preferable to checking for error results after script execution using APGScript.GetLastError().
<%# @LANGUAGE="VBScript" #%>
<%#
' Create a new APGen object
Dim oAPGen, oAPGScript
Set oAPGen = CreateObject("APGen")
' Turn debugging off
oAPGen.Debug = False
' Open the APG script
Set oAPGScript = oAPGen.OpenScript("default.apg")
' Use error handling - if a fatal error occurs in default.apg, Run
' raises an error.
On Error Resume Next
' Run it
oAPGScript.Run
' Turn off error handling
On Error GoTo 0
' Check if any errors occurred
Dim oAPGError
Set oAPGError = oAPGScript.GetLastError()
' Report if an error occurred
If (oAPGError.Number <> 0) Then
' Determine if the error was fatal
Dim sFatal
If (oAPGError.Severity = apgSeverityFatal) Then
sFatal = "Fatal Error"
Else
sFatal = "Non-fatal Error"
End If
' Format the error message
Dim sMsg
sMsg = sFatal & " Occurred while running " & oAPGError.Script.Path & _
"." & vbCRLF & vbCRLF & "Description: " & _
oAPGError.Description & vbCRLF & vbCRLF & _
"Source: " & oAPGError.Source & vbCRLF & _
"File: " & oAPGError.FilePath & vbCRLF & _
"Line Number: " & oAPGError.LineNumber
' Display a Message Box
MsgBox sMsg, vbExclamation, sFatal
End If
#%>