【问题标题】:Interesting way to catch all Rebol VID errors捕获所有 Rebol VID 错误的有趣方法
【发布时间】:2017-07-23 20:12:30
【问题描述】:

我偶然发现了这一点,只是想确保这不是 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
    ] 
]

【问题讨论】:

    标签: rebol rebol2


    【解决方案1】:

    这不是故障——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
        ]
    ]
    

    【讨论】:

    • 太好了 - 感谢您为我澄清这一点。这应该使我的程序的图形部分更加健壮。
    • 将永远循环与布局分开运行的优势到底是什么?除了清晰度?
    • @dogeye 清晰度是主要原因,是的。但是,您也可以从不使用事件系统每秒 1000 次中受益。
    猜你喜欢
    • 1970-01-01
    • 2010-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-14
    • 2016-12-28
    • 1970-01-01
    • 2013-04-19
    相关资源
    最近更新 更多