3

我偶然发现了这一点,只是想确保这不是 Rebol 设计中的故障。我有以下代码,它似乎成功地捕获了 VID 环境中的所有程序错误。

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
    ] 
]
4

1 回答 1

3

这不是小故障——<code>do-events 确实是调度程序,它会一直运行直到发生错误。我建议将错误处理程序与布局模型本身分离:

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
    ]
]
于 2017-07-23T21:30:32.000 回答