黑莓手机 - 全局异常处理 [英] BlackBerry - global exception handler

查看:107
本文介绍了黑莓手机 - 全局异常处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(编辑:这个问题是关于BB具体地说,是因为它优化了异常的奇怪的方式我很舒服,在J2SE正常的异常处理模式,但BB不表现为按正常具体来说在这种情况下,BB丢弃。错误类型和消息,以及如何BB开发者试图解决这个问题,或者如果他们忽略它。)

(edit: this question is about BB specifically, because of the strange way it optimises exceptions. I am comfortable with normal exception handling patterns in J2SE, but BB does not behave as per normal. Specifically in this case, BB discards the error type, and message, and how BB devs try to deal with this issue, or if they ignore it.)

我想实现某种形式的自定义全局的错误在我的BB的应用程序处理。特别是要尽量处理那些没有被我的code挂住的例外,因为我没想到他们。默认行为是该应用程序失败,并弹出一个对话框,说出现未知错误。

I would like to implement some form of custom global error handling in my BB app. Specifically to try to handle any other exceptions that were not caught by my code, because I had not expected them. The default behaviour is that the app fails, and a dialog pops up saying an Unknown error occured.

我想描述该错误的更好一点,因此我的所谓全局错误处理程序。类似code的内容:

I would like to describe the error a little bit better, hence my term "global error handler". Something similar to the code:

public static void main(String[] args)
{
    try
    {

        FusionApp app = FusionApp.getInstance();
        app.enterEventDispatcher();

    }
    catch (Throwable t)
    {
        // t has lost all type information at this point - this prints "null"
        System.err.println(t.getMessage());
    }
}

我的眼前的问题是,当我赶 T (在的main()的<$ C后的方法$ C> app.enterEventDispatcher()调用),它已经失去了类型信息。例如我知道,code抛出抛出:IllegalArgumentException 使用自定义的消息 - 但是在catch块,这是一个 java.lang.Error 消息。

My immediate problem is that when I catch t (in the main() method after the app.enterEventDispatcher() call), it has lost its type information. e.g. I know that the code throws an IllegalArgumentException with a custom message - however in the catch block, it is a java.lang.Error with null message.

和堆栈跟踪(ALT LGLG),消息也已经失去了(至少堆栈跟踪是准确的)。

And in the stack trace (ALT LGLG), the message has also been lost (at least the stack trace is accurate).

所以...什么是用来实现某种形式的全球错误处理对BB的良好格局?或者,这被认为是在这个平台上是一个坏主意?

So... what is a good pattern to use to implement some form of global error handling on BB? Or is this considered a bad idea on this platform?

它是好的做法,只是有未知的错误对话框弹出来 - 我不喜欢这样,但也许这是BB

Is it considered good practice to just have the unknown error dialog box pop up - I don't like this, but maybe that is the way of the BB?

推荐答案

最佳实践是实现自定义的异常处理。

Best practices are to implement custom exception handling.

所以,如果你希望赶上抛出:IllegalArgumentException,MyCustomException和StartupException,把它们放到catch块,然后再放入异常俘获(然后,如果你喜欢,放了抓的Throwable)

So, if you expecting to catch IllegalArgumentException, MyCustomException and StartupException, put them into catch block first, and then put an Exception catch (and then, if you like, put a Throwable catch)

常见的规则是 - 从最独家最常见的,和同级别的例外 - 从最有望至少有望

The common rule is - from most exclusive to most common, and for exceptions of the same level - from most expected to least expected.

在例外的情况下,== NULL或的getMessage()== NULL你总是可以显示类似应用程序错误,请发送事件日志[支持电子邮件]消息,那么如果你有一个很好的活动登陆后,您的应用程序,你有一个很好的机会来重现问题。

In case of exception == null or getMessage() == null you can always display something like "Application error, please send event log to [support email]" message, then if you have a nice event logging in you app, you have a good chance to reproduce an issue.

和谈论事件日志中,看到的事件记录类来实现记录。

And talking about event log, see EventLogger class to implement logging.

这篇关于黑莓手机 - 全局异常处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆