' Error Handling — Combined TRY/CATCH + ON ERROR patterns
#COMPILE EXE
#DIM ALL

FUNCTION PBMAIN() AS LONG
    LOCAL code AS LONG

    PRINT "=== ON ERROR GOTO pattern ==="
    ON ERROR GOTO Handler
    ERROR 10
    PRINT "After ERROR 10"

    ERRCLEAR
    PRINT "ERR after clear: "; ERR

    PRINT "=== TRY/CATCH pattern ==="
    'TRY
        PRINT "  TRY block executing"
        code = 1
    'CATCH
        PRINT "  CATCH block"
        code = -1
    'END TRY

    PRINT "Final code: "; code
    FUNCTION = 0

Handler:
    PRINT "Error "; ERR; " caught in handler"
    RESUME NEXT
END FUNCTION
