Look at the Javadoc for Lock.lock()
Implementation Considerations
A Lock implementation may be able to detect erroneous use of the lock, such as an invocation that would cause deadlock, and may throw an (unchecked) exception in such circumstances. The circumstances and the exception type must be documented by that Lock implementation.
Emphasis mine.
So by the contract it is allowed to throw an Exception
. This explains why the the second approach is wrong.