Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Regular Contributor
Posts: 71
Registered: ‎03-24-2010
My Device: 9550
My Carrier: Vodaphone

Re: Stack Traces and Throwable

I did a little experiment and now everything are clear (at least for me).

So I post it here and hope that they are helpful for you.

USE (THROWABLE)

public static void main(String[] args) {
        try {
            throw new IOException();
        } catch (Throwable ex) {
            ex.printStackTrace();
        }

       System.out.println("HELLO");
    }

 

In debug mode :  Program stops automatically at throw command and printStackTrace shows the full stack.

In run mode :  Program halts and shows "uncaught exception"


USE CATCH(EXCEPTION)

 

public static void main(String[] args) {
try {
throw new IOException();
} catch (Exception ex) {
ex.printStackTrace();
}

System.out.println("HELLO");
}

In both/debug mode :  Program only show NO STACK TRACE.


TO SUM UP:

- Although Exception implements Throwable, in RIM implementation, they are different.

- catch Exception won't stop your program during debug, and it does not have stack trace.

  So it does help debugging. It is for program logic (e.g. display an error to user).

- catch Throwable is for debugging. It does not effective when application run. But when it you debugging it, it will stop and and show the full stack trace. (So, never use catch Throwable to catch and solve exception because it is not effective during runtime).


Hai Ly


 

 

Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Stack Traces and Throwable

I disagree with your conclusions.

 

We use "catchThowable" in production because this forces the stack trace to appear in the device event log. This stack trace is the "court of last resort" when we have a production problem on a customer device that we cannot duplicate on our test devices.

 

 

Regular Contributor
Posts: 71
Registered: ‎03-24-2010
My Device: 9550
My Carrier: Vodaphone

Re: Stack Traces and Throwable

Yes, I agree with you.

Now, I'm confusing again:

- If we use catch exception (e.g. to report that file does not exist) to show some message, then we don't have any stack trace.

- If we use catch throwable, then we have stack trace but when application run in production, no message will be shown to the user, in stead the user will receive uncaught exception.

 

Hai

Developer
Posts: 1,746
Registered: ‎04-08-2010
My Device: Passport Silver, PRIV
My Carrier: Telekom.de, O2, Vodafone

Re: Stack Traces and Throwable

thx for all the informations from this thread

 

I referenced this thread from my blog

 

HowTo catch Exceptions

 

where I talked about my experiences with Exceptions, Throwables and missing StackTraces

-------------------------------------------------------------------------------
ekke (independent software architect, rosenheim, germany)

BlackBerry Elite Developer
BlackBerry Platinum Enterprise Partner
International Development native Mobile Business Apps
BlackBerry 10 | Qt Mobile (Android, iOS)
Workshops / Trainings / Bootcamps

blog: http://ekkes-corner.org
mobile-development: http://appbus.org Twitter: @ekkescorner
Highlighted
Developer
Posts: 131
Registered: ‎03-25-2009
My Device: Z30
My Carrier: Telus

Re: Stack Traces and Throwable

Sorry to dig up an old thread, but I am and trying to track down an exception that a user is getting, but I can't reproduce.  I have a logging system setup so that the user can email me a log with a click of a button, that is how I know an exception is occurring.  But I would like to an a stack trace to this message. 

 

I came accross this thread, and am kind of in disbelief, that I am unable to do this. I mean if I catch Throwable, I can do a printStackTrace() but this doesn't help me at all.  I need to write the stack trace to my file, not System.err. In other java profiles, printStackTrace is overloaded to take a print stream, as well other profiles have the getStackTrace() available to them off of Throwable.  I don't understand the logic of Throwable not implementing getStackTrace()?

 

Surely in 2011 we have a way to iterate over a stack trace?