Fun Way to Catch All Vid Rebol Errors

I stumbled upon this and just wanted to make sure it wasn't a glitch in Rebol's design. I have the following code that seems to successfully catch all program errors in the VID environment.

view layout [ 
    across    
    label  "Rebol Command:" 
    f: field [
       do f/text 
       focus f     
    ] return 
    button "Error 1" [
        print this-is-an-error-1
    ]
    button "Error 2" [
        print this-is-error-2
    ]

    time-sensor: sensor 0x0 rate 1000 
    feel [
        engage: func [face action event] [
            if action = 'time [
                time-sensor/rate: none
                show face
                if error? err: try [
                    do-events
                    true ; to make the try happy
                ][
                    the-error: disarm :err 
                    ? the-error
                    ; reset sensor to fire again
                    time-sensor/rate: 1000
                    show face
                    focus f
                ]
            ]
        ] 
    ]
    do [
        focus f
    ] 
]

      

+3


source to share


1 answer


This is not a glitch - it do-events

really is a dispatcher that will run until an error occurs. I would suggest decoupling the error handler from the layout model itself, though:



view/new layout [ 
    across    
    label  "Rebol Command:" 
    f: field [
       do f/text 
       focus f     
    ] return 
    button "Error 1" [
        print this-is-an-error-1
    ]
    button "Error 2" [
        print this-is-error-2
    ]
    do [
        focus f
    ] 
]

forever [
    either error? err: try [
        do-events
    ][
        the-error: disarm :err 
        ? the-error
        focus f
    ][
        break
    ]
]

      

+3


source







All Articles