What's the difference between the code inside a finally clause and the code located after catch clause?
- by facebook-100005613813158
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.