Here is an example of an exception happening inside a lock, with a try-catch block.
int zero = 0; int j = 10; lock (sharedResource.SyncRoot) { try { j = j / zero; } catch (DivideByZeroException e) { // exception caught but lock not released } }
How do I safely release this lock in the catch?
Won’t it be released automatically?
From the MSDN lock means
So you don’t have to bother.