在 Blackberry Java 中捕获 Throwable:好主意吗?

发布于 2024-10-21 22:41:29 字数 376 浏览 3 评论 0原文

我经常在 Blackberry 文档中看到 Throwable 的 catch 子句,例如 网络 API 文档。我的感觉是,这在 Java 中通常不是一个好的做法。

黑莓编程中有这个原因吗?

它与堆栈跟踪生成有关吗对于可抛出的?

I often see catch clauses for Throwable in Blackberry documentation, such as the Network API docs. My sense is that this is not generally a good practice in Java.

Is there a reason for this in Blackberry programming?

Does it have to do with stack trace generation for Throwables?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

陌若浮生 2024-10-28 22:41:30

当您在 BlackBerry 应用程序中捕获 Throwable 时,它​​不仅会保留堆栈跟踪,还会将该堆栈跟踪保存在设备事件日志中。 应用程序本身无法获取堆栈跟踪,因此遗憾的是您无法自动收集堆栈跟踪。

要查看堆栈跟踪,请打开事件日志查看器。对于带有物理键盘的黑莓,按住“Alt”,然后按 LGLG 以调出事件日志。

When you catch Throwable in a BlackBerry app, not only does it preserve the stack trace, it saves that stack trace in the device event log. There is no way for an app to get a stack trace itself, so unfortunately you can't automatically collect stack traces.

To view the stack trace, you pull up the event log viewer. For blackberries with physical keyboards, hold 'Alt' and then press L G L G to bring up the event log.

知你几分 2024-10-28 22:41:30

阅读 java.lang.Error 的文档,它是 Throwable 的子类,您会看到捕获 Throwable 的问题。

它说:

Error 是 Throwable 的子类
这表明存在严重问题,需要合理应用
不应该试图抓住。

例如,您最终可能会无意中捕获 VirtualMachineError,表明整个虚拟机处于损坏状态。将某些内容放入finally 块中以在损坏的VM 上运行似乎不是一个好主意。

Read the documentation for java.lang.Error, which is a subclass of Throwable, and you'll see the problem with catching Throwable.

It says:

An Error is a subclass of Throwable
that indicates serious problems that a reasonable application
should not try to catch.

For example, you could end up inadvertently catching a VirtualMachineError indicating the whole VM is in a broken state. Putting something in the finally block to run on broken VM doesn't seem like a good idea.

-柠檬树下少年和吉他 2024-10-28 22:41:30

我不认为有什么特别的原因。看评论:

} catch (Throwable t) { // 还可以捕获特定异常,以包含不同类型的特殊hadling

这意味着该示例是基本的。并且有一个错字和一个不好的做法。因此,如果可能的话,捕获特定的异常。

I don't think there's a special reason. See the comment:

} catch (Throwable t) { // can also catch specific exceptions to include special hadling for the different types

It means the example is basic. And has a typo, and a bad practice. So catch specific exceptions if possible.

浮光之海 2024-10-28 22:41:30

在 BB 平台上,如果 Throwable 被捕获,它会保留堆栈跟踪并通常将其呈现在屏幕上,在用户面前爆炸。对于用户体验来说不太好:(

当捕获异常(和扩展类)时,出于效率原因,堆栈跟踪将被丢弃。

On the BB platform, if Throwable is caught it preserves the stacktrace and usually renders it on the screen, blasting in the user's face. Not very good for UX :(

When Exception (and extended classes) are caught the stacktrace is thrown away for efficiency reasons.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文