I am trying to understand the mechanism when i use finally inside a while loop. In the below code. In finally line prints and than the while breaks. I was expecting the code not to reach the finally block. Or if it reaches the finally block, there is no break there so the while should continue.. Can anyone explain how this works ?
while(true){
System.out.println("in while");
try{
break;
}finally{
System.out.println("in finally");
}
}
System.out.println("after while");
Output is
in while
in finally
after while