File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Missing stack trace.

 
Naresh Chaurasia
Ranch Hand
Posts: 361
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Naresh Chaurasia
Ranch Hand
Posts: 361
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even if i am returning the program control, it does not give any stack trace.


 
E Armitage
Rancher
Posts: 989
9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 1089
14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic