12-28-2009 06:45 PM
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?
12-28-2009 07:27 PM
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.
12-28-2009 07:32 PM
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?
12-28-2009 07:39 PM
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.
12-28-2009 07:45 PM
The exceptions are thrown all over the place.
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.
12-28-2009 09:12 PM
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 RexDoug said) and as time went on nobody gave thought to removing it.
12-29-2009 03:49 AM - edited 12-29-2009 03:57 AM
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...
12-29-2009 08:25 AM
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.
12-29-2009 08:38 AM
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.