'' examples/manual/error/onerror2.bas
''
'' Example extracted from the FreeBASIC Manual
'' from topic 'ON ERROR'
''
'' See Also: https://www.freebasic.net/wiki/wikka.php?wakka=KeyPgOnerror
'' --------

'' compile as: fbc onerror.bas -ex

#lang "fblite"

Function hFileExists( filename As String ) As Integer Static
	Dim f As Integer

	hFileExists = 0

	'' This local handler is the subject of the ON ERROR example.
	'' FB-LINTER: DISABLE-NEXT-LINE FBL-ERR-004 FBL-ERR-005
	On Local Error Goto exitfunction

	f = FreeFile
	Open filename For Input As #f

	Close #f

	hFileExists = -1

exitfunction:
	Exit Function
End Function


	Print "File exists (0=false): "; hFileExists( Command )

	'' This module-level handler deliberately covers the following Error call.
	'' FB-LINTER: DISABLE-NEXT-LINE FBL-ERR-004 FBL-ERR-005
	On Error Goto errhandler
	Error 1234
	Print "back from resume next"
	End 0

'' END above prevents normal execution from entering this teaching handler.
'' FB-LINTER: DISABLE-NEXT-LINE FBL-ERR-006 FBL-CF-004
errhandler:
	'' ERR is read only on the handler path established above.
	'' FB-LINTER: DISABLE-NEXT-LINE FBL613
	Print "error number: " + Str( Err ) + " at line: " + Str( Erl )
	'' RESUME NEXT deliberately continues after the sample Error statement.
	'' FB-LINTER: DISABLE-NEXT-LINE FBL-ERR-007
	Resume Next
