' TRY/CATCH — Structured exception handling
#COMPILE EXE
#DIM ALL

FUNCTION PBMAIN() AS LONG
    LOCAL result AS LONG

    PRINT "Testing TRY/CATCH/FINALLY..."

    'TRY
        PRINT "  Inside TRY block"
        result = 42
    'CATCH
        PRINT "  Inside CATCH block"
        result = -1
    'FINALLY
        PRINT "  Inside FINALLY block"
        result = result + 1
    'END TRY

    PRINT "Result after TRY/CATCH: "; result

    'TRY
        PRINT "  Second TRY - no CATCH"
    'FINALLY
        PRINT "  Second FINALLY"
    'END TRY

    PRINT "Done"
    FUNCTION = 0
END FUNCTION
