Side effects of throwing an exception inside a synchronized clause?

Yossale picture Yossale · Jan 7, 2010 · Viewed 18.9k times · Source

Are there any unclear side effects to throwing an exception from within a synchronized clause? What happens to the lock?

private void doSomething() throws Exception {...}

synchronized (lock) {   
    doSomething();       
}

Answer

KLE picture KLE · Jan 7, 2010

I see no side-effect.

The lock is guaranteed to be terminated in all cases, and an exception is no exception (pun intended).