(这是 Groovy 1.8.9。问题已在 Groovy 2.1.0-rc-1 中修复)
我正在尝试处理SwingBuilder.doOutside{}
. 我用过Thread.setDefaultUncaughtExceptionHandler()
,但它似乎没有拦截doOutside{}
.
这是一个说明问题的示例程序。如果我从命令行运行它并单击EDT Exception按钮,我printStackTrace()
会在 stderr 上看到结果。如果我单击Outside Exception,则没有任何显示。我究竟做错了什么?
import groovy.swing.SwingBuilder
class ExceptionTest {
static main(args) {
Thread.setDefaultUncaughtExceptionHandler(
{ thread, exception ->
System.err.println "thread ${thread.getName()}"
exception.printStackTrace()
} as Thread.UncaughtExceptionHandler)
def swing = new SwingBuilder()
def testEDTButton = swing.button('EDT exception')
testEDTButton.actionPerformed = { throw new Exception("EDT exception") }
def testOutsideButton = swing.button('Outside Exception')
testOutsideButton.actionPerformed = { swing.doOutside { throw new Exception("Exception outside") } }
def frame = swing.frame(title: 'Test exception reporting') {
vbox {
widget(testEDTButton)
widget(testOutsideButton)
}
}
frame.pack()
frame.show()
}
}