1

(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.)

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.

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());
    }
}

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.

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

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?

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?

Richard Le Mesurier
  • 29,432
  • 22
  • 140
  • 255
  • Hey Richard I am a co-founder at BugSense. We specialize in error tracking for mobile apps. It would be great if we have chat about the BlackBerry platform. Feel free to contact us on our website – PanosJee Jul 08 '11 at 13:54

1 Answers1

0

Best practices are to implement custom exception handling.

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.

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.

Maksym Gontar
  • 22,765
  • 10
  • 78
  • 114
  • thanks, this is great info. However I am after a BB specific solution, to find out what other BB devs do in this case. I have edited the question a bit to be more specific that I want to have some sort of try..catch block over the whole app to handle unexpected exceptions like a null pointer, illegal argument etc, and handle them in a nice way for the user. – Richard Le Mesurier May 25 '11 at 06:06