说,如果我在 C# 代码上有以下块:
public class SynchedClass
{
public void addData(object v)
{
lock(lockObject)
{
//Shall I worry about catching an exception here?
//Do the work
//arr.Add(v);
}
}
private List<object> arr = new List<object>();
private object lockObject = new object();
}
我应该尝试在lock
块内捕获异常吗?(我主要担心的是锁内可能会引发异常,这将阻止锁被“解锁”。)