如何在 SWT 事件循环中捕获未经检查的异常
我想问题很清楚,我想捕获(并记录)SWT 事件循环中发生的 RuntimeException。现在,我将对代码的所有调用包装在 Runnable 中,该 Runnable 会记录任何 RuntimeException,但这有一些缺点,例如添加大量样板代码并且无法捕获第三方 gui 库中的异常。
i guess the question is pretty clear, i want to catch (and log) RuntimeException that occur in SWT's event-loop. Right now i'm wrapping all my calls to code in a Runnable which logs any RuntimeException, but this has drawbacks like adding a lot of boilerplate-code and not being able to catch exceptions in third-party gui-libraries.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以创建一个
UncaughtExceptionHandler
当抛出异常并且未在代码中的某个位置捕获异常时将调用该异常。这使您可以在最后一刻完成您想要实现的记录。这是更多 详细文章展示了如何使用处理程序。You can create an
UncaughtExceptionHandler
that will be called when an exception is thrown and not caught somewhere in the code. This allows you do to the last minute logging you want to achieve. Here is a more detailed article that shows how you can use the handler.