OnErrorGoto()

Syntax

OnErrorGoto(?LabelAddress)
Description
Changes the action taken when an error occurs to jump to the specified label address and continue program execution there. After the jump to the label, the functions of this library can be used to get further information about the error.

Parameters

?LabelAddress The address of a label in the program to jump to.

Return value

None.

Remarks

The program stack will not be adjusted before jumping to the label, so local variables should not be accessed as they may not be reachable anymore. It is also not safe to continue normal program execution after an error as things like the return address of a procedure may be wrong if the stack is no longer correct. The best practice is just to gather and display information about the error and then exit the program.

Example

  MessageRequester("OnError test", "Test start")

  OnErrorGoto(?ErrorHandler)
  Pokes(10, "Hello World") ; Cause a #PB_OnError_InvalidMemory error
  
  MessageRequester("OnError test", "This should never be displayed")
  End
  
  ErrorHandler:
  MessageRequester("OnError test", "The following error happened: " + ErrorMessage())
  End

Supported OS

All

<- OnErrorExit() - OnError Index - RaiseError() ->