aspose file tools*
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Missing stack trace." Watch "Missing stack trace." New topic
Author

Missing stack trace.

Naresh Chaurasia
Ranch Hand

Joined: May 18, 2005
Posts: 356
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: 356
Even if i am returning the program control, it does not give any stack trace.


E Armitage
Rancher

Joined: Mar 17, 2012
Posts: 761
    
    9
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
Bartender

Joined: Sep 06, 2012
Posts: 839
    
  14
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.

Chan.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Missing stack trace.
 
Similar Threads
StackTrace
Exception Handling
Different output while using printStackTrace()
Exception
methods throwing exceptions!!!!!!