Click here to Skip to main content
15,894,252 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
try{
statement1;
statemnent2;
statement3;
}
catch(Exception1 ex1){
}
finally{
statement4;
}
statement5;

What I have tried:

which Statements will execute if no exception is occurs? which Statements will execute if Exception 1 is occurs at statement?
Posted
Updated 31-Mar-20 1:43am
Comments
MadMyche 31-Mar-20 7:45am    
What do you think the answers are? Have you written any code to test this?
Richard MacCutchan 31-Mar-20 8:36am    
Think about it, it is a simple (but rather a bad example) logic question.

1 solution

We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!

Start by thinking about what try ... catch ... finally does and then try generating "mental exceptions" to see what happens when a problem occurs when each statement in turn.
Then try the code: replace the statements with system.out.println instructions and see what happens when you execute them. Then do a divide by zero or similar to cause an exception and try again. When it matches what you figured, you can write up your homework!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900