File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Missing stack trace. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Missing stack trace." Watch "Missing stack trace." New topic

Missing stack trace.

Naresh Chaurasia
Ranch Hand

Joined: May 18, 2005
Posts: 361
I have following code:

The output of the program is : 10. After the 10 is displayed there is no stack trace shown in console.

If i change the program to following code:

The stack trace is displayed. Why this different behavior. In the first case why no stack trace is displayed.

SCJP 1.4, SCWCD1.4, OCA(1Z0-007)
Naresh Chaurasia
Ranch Hand

Joined: May 18, 2005
Posts: 361
Even if i am returning the program control, it does not give any stack trace.

E Armitage

Joined: Mar 17, 2012
Posts: 989
The exception was being thrown because it is left to the runtime to propagate it out because the try just marked the exception status.
When you put a return in the finally you explicitly handle the exit status of the try block and since the finally is always executed it will override the exception status that was set earlier. That is why you should never return from a finally block. Most IDEs will give you a warning if you have a finally that does not complete normally.
Chan Ag

Joined: Sep 06, 2012
Posts: 1089
To add to what E Armitage has said, having a control transfer instruction in the finally block is in general not a good idea.

It is also a bad programming practice to have other control transfer instructions like continue in the finally block.

I agree. Here's the link:
subject: Missing stack trace.
It's not a secret anymore!