Make sure lock is unlocked even after an exception by wrapping it in a try finally