;
; -------------------------------------------------------------------------
;
;  PureBasic - OnError
;
;  More examples can be found in the "PureBasic\Sources\OnError" drawer
; 
;  You need to disable the PureBasic debugger to have it working.
;
; --------------------------------------------------------------------------
;

; If there is an error, jump to the CatchError label.
OnErrorGoto(?CatchError) 


; Tell this the user:
MessageRequester("Information!","The program will jump to the CatchError label,"+Chr(13)+Chr(10)+"and display a message in case of an error.")

; Now some code with bugs in it:

Null.l=0                  ;1. division by 0
Ergebnis.l = 123 / Null

!INT 3                    ;2. asm breakpoint


PeekL(99)                 ;3. reading memory at a forbidden area


; the program will end before this, because of the above errors.
MessageRequester("Information!","This will never be executed!")
End


; This is the Goto label, which will be executed in case of an error.
CatchError:


Msg$ = "There was an error:"+Chr(13)+Chr(10)+Chr(13)+Chr(10)
Msg$ + "Description: " + GetErrorDescription()+Chr(13)+Chr(10)
Msg$ + "Total number of errors: "+Str(GetErrorCounter())+Chr(13)+Chr(10)+Chr(13)+Chr(10)
Msg$ + "The program will end now."

MessageRequester("Error!", Msg$)

; Now end the program, because we can't jump back after OnErrorGoto()
End
; ExecutableFormat=Windows
; DisableDebugger
; EOF