• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exceptions

 
Carlo Leeuwen
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
The question is what will be printed after this code has run:


The answer seems to be:
"The program will print 1, 4 and 5, in that order."

But I don't understand why '5' is printed. After the finally, shouldn't the main method be done? Can anyone explain me?

Thanks in advance!
 
Kelvin Chenhao Lim
Ranch Hand
Posts: 513
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Carlo,

When a program reaches the end of a "finally" block, it does not then exit the current method. Rather, it continues on to the next line after the whole "try..catch..finally" construct.

Don't be confused by the keyword "finally". Despite the name, it's not that final. It's only "final" with respect to the "try..catch..finally" construct that it's a part of.
 
Carlo Leeuwen
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok thanks, I guess I mixed up some things.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic