What's the difference between the code inside a finally clause and the code located after catch clause?
Posted
by
facebook-100005613813158
on Programmers
See other posts from Programmers
or by facebook-100005613813158
Published on 2013-10-18T01:47:48Z
Indexed on
2013/10/18
4:11 UTC
Read the original article
Hit count: 230
java
|exceptions
My java code is just like below:
public void check()throws MissingParamException{
......
}
public static void main(){
PrintWriter out = response.getWriter();
try {
check();
} catch (MissingParamException e) {
// TODO Auto-generated catch block
out.println("message:"+e.getMessage());
e.printStackTrace();
out.close();
}finally{
out.close();
}
//out.close();
}
Then, my confusion is: what the difference if I put out.close()
in a finally code block or if I just remove finally code block and put out.close()
behind catch clause (which has been commented in the code). I know that in both ways, the out.close()
will be executed because I know that whether the exception happened, the code behind the catch clause will always be executed.
© Programmers or respective owner