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

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -