Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

try catch finally sequence

 
Shankar Narayana
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am very well aware of the situation in which the try, catch and finally work but i have a program code for which i am not able to determine what the sequence is..

Here goes the code:


Now my question is what happens if there is a Sql error in the case 1, will the finally be executed and then the error is caught or only the error is caught without finally.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The "finally" is executed before the catch blocks are entered.
 
Shankar Narayana
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so what happens to the exception, is it caught or left.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It goes "through" the finally block and is caught.
 
Ulas Ergin
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if an exception occurs in the try block of case 1
*first finally block of the try in case 1 will be executed
*exception will be handled by the catch block of the outer try since you have no catch block in the case 1's try
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic