aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Exception" Watch "Exception" New topic
Author

Exception

Neha Sawant
Ranch Hand

Joined: Oct 11, 2001
Posts: 204

Hi,
public class test{
static string s="";
public static void metod(int i){
try{
if(i==2){throw new Exception();
}
s+=1;
}
catch (Exception e)
{
s+=2;
return;}
finally
{
s+=3;
}
s+=4;
}
public static void main (String args[])
{
method(1);
method(2);
Sytem.out.println(s);
}
prints 13423
but i feel it should be 134234 since the exception is caught the line after finally should be executed.
Please could someone help me on this
Regards
Neha


nss
Fei Ng
Ranch Hand

Joined: Aug 26, 2000
Posts: 1242
If there is no return in catch(){.... return;} you are right.
But there is a return statment. Before the return; in catch(){} the final {} gets to run and then back to the return statement.
I think you know this already, just make sure you read all the code.

[This message has been edited by FEI NG (edited December 02, 2001).]
Sonali Joshi
Greenhorn

Joined: Dec 01, 2001
Posts: 8
Thanx FEING
I was not aware of this.
Now that my exam date is coming near i am getting all the more confused.
Thnk you once again
Regards
Neha


sj
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
How come the same guy has two different names ??
Neha Sawant and Sonali Joshi, which one really exists?

------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception
 
Similar Threads
flow control
finally block
can't understand the output
Please Help with the flow of this code
COnfusion About Unreachable Code