if (errorList != null && errorList.count() > 0) { foreach (var error in errorList) { throw new Exception(error.PropertyName + " - " error.ErrorMessage,error.EntityValidationFailed); } }
为什么在列表中出现多个错误时只抛出一个异常?
所以代码如下:
foreach (var error in errorList) { try { throw new Exception(error.PropertyName + " - " error.ErrorMessage,error.EntityValidationFailed); } catch(...) {} }
将引发多个异常,准确地说是errorList.Length次,这将由catch(..)处理,如果没有从catch(..)中重新抛出,将保留在循环体内.