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
New Developer
Posts: 2
Registered: ‎11-19-2009
My Device: Not Specified

Stack Traces and Throwable

From the javadoc for Throwable:

 

RIM Implementation Note

Only uncaught exceptions have stack traces. The VM checks the current catch stack and if it finds anything that will catch the exception, it eliminates the stack trace to save time and memory. Any code in the current stack such as catch (Exception e) eliminates the stack trace.

If the exception is never caught, then the stack trace is generated.The stack trace is also generated if there is code such as catch (Throwable t).

 

Is this a joke?

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Stack Traces and Throwable

Welcome!

 

I think your quotation is an accurate description of what happens.

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

Re: Stack Traces and Throwable

Unfortunately, the joke is on us.

 

Here is the punch-line:

 

1. There is no way to write the stack trace to your own log file

2. The system event log (which contains the trace) is not accessible programmatically.

 

Smiley Happy

 

 

 

New Developer
Posts: 2
Registered: ‎11-19-2009
My Device: Not Specified

Re: Stack Traces and Throwable

Thanks for the welcome. I'm relatively new to blackberry development, so I'm having a little bit of trouble with this. If exceptions are only thrown in exceptional situations, then how big would the performance hit have to be for it not to be worth it? Is this leftover from when the devices were much slower?

Developer
Posts: 562
Registered: ‎09-30-2009
My Device: Not Specified

Re: Stack Traces and Throwable

Exceptions are not generally thrown always in "exceptional circumstances", they may be thrown with something as benign as trying to open a file that doesn't exist, for example.

 

The idea is that if you catch an exception, you generally have some idea of where it is, because you caught it -- however, because of the note, you won't know what the stack looks like at the time. But at least you have a starting point.

 

If you miss catching an exception, say, in a method, the compiler will want you to declare the method as throwing an Exception, and that Exception may propagate up the stack, so having a stack trace in this instance is much more valuable, otherwise you won't know exactly where it happened.

 

I suppose this is the compromise that is aimed for here.

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

Re: Stack Traces and Throwable

The exceptions are thrown all over the place. Smiley Happy

 

The trace is logged only retained only if you catch Thowable (as opposed to a specific Exception).

 

I agree that it is ridiculous, and I assume that this is a holdover from the early days of the platform.

 

Even if you catch Throwable in strategic places, you will be lucky to find a user who can a) start the log viewer, b) find the exception, and c) copy the stack trace to an email - this is the only way to perform problem determination on some guys phone who is 1,000 miles away.

 

 

Highlighted
Developer
Posts: 1,807
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.3.2.858, Z10 (STL100-3)-10.3.1.2576, Z30 (STA100-5)-10.3.1.2582, Passport (SQW100-1)-10.3.1.2576, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: Stack Traces and Throwable

Doesn't that seem backwards? Wouldn't it be if you were going to catch an exception that you might want to know the StackTrace but if you weren't going to catch it that the StackTrace is unnecessary?

 

This is most likely so basic that they did that odd implementation for the early BlackBerrys (as  said) and as time went on nobody gave thought to removing it.

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Developer
Posts: 562
Registered: ‎09-30-2009
My Device: Not Specified

Re: Stack Traces and Throwable

[ Edited ]

If you don't have a stack trace for an uncaught exception, how do you know what generated it, especially if the exception gets passed up the stack?

 

If you catch an exception, you obviously know where the exception is caught, so you have an idea of the stack structure already.

 

ed. Perhaps I'm thinking too much about this in a desktop context -- if you have an uncaught exception, the OS will kill the application...

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

Re: Stack Traces and Throwable

I believe that an uncaught exception *does* log the stack trace in the system event log.

 

Of course, it also terminates your application.

 

We have a "catch-all" catching Throwable so that when all else fails, we can restart the app and still get the exception trace logged.

 

My personal opinion, I cannot think of a single legitimate reason for removing the stack trace. Having access to the trace is invaluable in problem determination. I'd love to know what the current justification is for this.

 

 

Developer
Posts: 67
Registered: ‎10-14-2009
My Device: Not Specified

Re: Stack Traces and Throwable

Jup, totally uncaught exceptions show up in the eventlog of the device.

However they are comparably bad to read compared to normal java exceptions.

 

What annoys me most is that the exception trace gets removed the moment you catch it, instead of at some later point like at the end of the catch clause orso. Not having printStackTrace is realy annoying.

 

-------------
blog: http://coding.westreicher.org
twitter: http://www.twitter.com/meredrica