c# - Exceptions inside the lock block -
say, if have following block on c# code:
public class synchedclass { public void adddata(object v) { lock(lockobject) { //shall worry catching exception here? //do work //arr.add(v); } } private list<object> arr = new list<object>(); private object lockobject = new object(); } shall attempt catch exceptions inside lock block? (my main concern exception may raised inside lock prevent lock being "unlocked".)
lock released when exception escapes lock block.
that because lock(){...} translate compiler into:
monitor.enter(obj); try{ // contents of lock block }finally{ monitor.exit(obj); }
Comments
Post a Comment