Added tests for unexpected exception inside locked code.