Catching Throwable in Blackberry Java: Good Idea?

2019-03-05 08:49发布

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?

4条回答
Explosion°爆炸
2楼-- · 2019-03-05 08:51

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.

查看更多
姐就是有狂的资本
3楼-- · 2019-03-05 08:52

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.

查看更多
Explosion°爆炸
4楼-- · 2019-03-05 08:54

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.

查看更多
Evening l夕情丶
5楼-- · 2019-03-05 09:07

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.

查看更多
登录 后发表回答