Catch exceptions when lock held to make sure to release it.