我得到以下代码中的用户代码未处理 ServiceRuntimeException,其中 ServiceRuntimeException 是自定义异常,如何解决?
List<Action> a=new List<Action>();
try
{
foreach (var parallelActivity in parallelActivities)
{
a.Add(delegate
{
try
{
parallelActivity.Execute();
}catch(ServiceRuntimeException e)
{
throw e;//<--Exception thrown at this line
}
});
}
Parallel.Invoke(a.ToArray());
}
catch (ServiceRuntimeException e)
{
throw e;
}catch(AggregateException e)
{
throw e.InnerExceptions[0];
}
ServiceRuntimeException的定义
public sealed class ServiceRuntimeException : Exception
{
public ServiceRuntimeException(string msg)
: base(msg)
{
}
}