Arbortext IsoDraw > Macro Language Reference > Introduction > Language Basics > Flow Control Statements > On Error Goto
  
On Error Goto
Applies to Arbortext IsoDraw 7.0 F000 and later.
This command defines a local error handling routine that is called as soon as an error is detected. The error handling routine only applies to the subMacro or macro that contains the ON ERROR GOTO command; the routine does not extend to the calling macro.
An error handling routine is not active until the ON ERROR GOTO command line executes.
ON ERROR GOTOmacrocall
macrocall
A macro or subMacro name. It is possible to add a valid list of parameters in brackets. Any specified variables and expressions will be evaluated at runtime when the error handling routine starts.
SUBMACRO IgnoreErrorHandler
# Use an empty SubMacro as ErrorHandler
# to ignore all errors.
END SUBMACRO

SUBMACRO StandardErrorHandler( string sLine )
# This SubMacro simulates the standard error behaviour.
ERROR app.lastMacroError sLine
END SUBMACRO

SUBMACRO GermanErrorMessageBox( string sLine )
# Example for custumized error handling
DEFINE s AS string
s = "Fehlernummer: " + app.lastMacroError
s = s + $newline + "Zeile: " + sLine
MESSAGE s
END SUBMACRO

SUBMACRO DumpErrToFile( string sOut )
# Write Error Messages to own file
DEFINE nErr AS integer
nErr = app.lastMacroError
FWRITE sOut nErr +" "+ errorString( nErr, "..." )
END SUBMACRO

SUBMACRO MyErrorHandler( string sLine )
DEFINE nErr AS integer
nErr = app.lastMacroError
# Handle specific error situation:
IF ( nErr= 400 ) THEN
MESSAGE "Error number 400: caught it!"
Return
END IF
# Force standard error message as default:
ERROR nErr sLine
END SUBMACRO

#------------------------------------------------------
SUBMACRO IML_CheckErrorCode
DEFINE nErr AS integer
DEFINE sMsg AS string
ON ERROR GOTO MyErrorHandler( \
app.currentMacro.activeLine )
sMsg = "Please enter an error number: [400]"
nErr = GET integer sMsg
ERROR nErr
END SUBMACRO

SUBMACRO IML_DumpErrorMessages
# Dump some system and macro error messages to a file.
DEFINE i AS integer
DEFINE sOut AS string
sOut = "C:\err_msgs.txt"
FNEW sOut 8_bit
ON ERROR GOTO DumpErrToFile( sOut )
FOR i=-1 TO -20 STEP -1
ERROR i
END FOR
FWRITE sOut "--------------"
FOR i=400 TO 420
ERROR i
END FOR
END SUBMACRO

Macro IML_ErrorHandling_Example

# Trigger error without installed handler:
# (If you delete the comment sign from the following line the macro will
# not be executed beyond this line!)

# ERROR -1 "Just kidding!"

# Ignore the triggered errors
ON ERROR GOTO IgnoreErrorHandler
ERROR -1
ERROR 400 "Can you see me?"
MESSAGE "No, you can't!"

# Pass a parameter to the error handler
# (The parameter values will not be evaluated until the error occurs!)
ON ERROR GOTO GermanErrorMessageBox( \
app.currentMacro.activeLine )
MESSAGE 100/0

# Installed message handler only affects the local file
Run IML_CheckErrorCode

# Error handler "GermanErrorMessageBox" is still
# active here
ERROR "User triggered error"

# A less trival example
Run IML_DumpErrorMessages

# Break macro execution on errors again...
ON ERROR GOTO StandardErrorHandler( \
app.currentMacro.activeLine )
ERROR -1 "Just kidding!"
END Macro