About Question com.enthuware.ets.scjp.v6.2.396 :
Posted: Tue Apr 10, 2018 2:39 am
				
				Am I correct in supposing that this only applies to a situation where the exception is thrown out of the method?If a synchronized method throws an exception in its execution, any locks acquired by the method are released automatically.
If an exception is thrown during a method's execution, but it's caught within that method, would any acquired locks would still be held?
For example
Code: Select all
class SynchronizedMethodTest{
  synchronized void m(){
    try{
      //do dangerous stuff
      throw new Exception();
    }catch(Exception e){}
    //method still has lock on class instance at this point? [A]
  }
  public static void main(String[] args){
    new SynchronizedMethodTest().m();
  }
}