• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

exceptions

 
Martin Smith
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
look at this code - It's like the exception gets "lost" - odd or what?
 
Greg Charles
Sheriff
Posts: 2985
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The purpose of a finally block is to execute some code regardless of how you exit the try block. That is, you could finish executing the try block normally, return from the inside the block, or throw an exception from inside the block. The finally block is great for closing an I/O stream, socket, db connection, or something similar. You've chosen to put a return statement there though. The exception stops execution of the try block, but the finally block still executes and returns true. You cannot both return a value and throw an exception from a method, so the exception "disappears".
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yup. It's almost always a bad idea to return or throw an exception from a finally clause. Note that the new JDK, j2sdk1.4.2 (beta), will give you a warning when you compile this class:
warning: finally clause cannot complete normally
 
Martin Smith
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thx!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic