Catching exception while releasing locks