如何立即抛出 List<CustomExceptionObj> 异常

Abh*_*hid 3 .net c# asp.net wcf visual-studio

我有一个 wcf 服务,现在我已对其进行了更改,以在异常发生时继续将异常编译到列表中,并在最后将此列表作为错误响应抛出。现在单个错误就可以了。我能够抛出它并获得输出。但事实证明,将列表作为错误抛出有点具有挑战性。

-到目前为止我已经尝试过:使用AggregateException。我尝试四处寻找适当的实现。到目前为止,想出了这个:

throw new AggregateException("Multiple Errors Occured", ExceptionsList)
Run Code Online (Sandbox Code Playgroud)

还,

List<CustomExceptionObject> ThrowException(List<CustomExceptionObject> ExceptionList)
{
AggregateException eggExp = new AggregateException(ExceptionList);
throw new eggExp;
}
Run Code Online (Sandbox Code Playgroud)

我使用这些方法不断收到未处理的异常错误。任何见解都值得赞赏。

更新:我不断收到的错误消息是 -

An exception of type 'System.AggregateException' occurred in XYZ.dll but was not handled in user code.
Run Code Online (Sandbox Code Playgroud)

请记住,抛出 CustomExceptionObject 的单个对象会在 SOAP UI 中抛出正确的错误响应。我似乎无法列出这些例外情况。

Tay*_*ren 6

聚合异常是引发异常集合的正确方法。

throw new AggregateException("Multiple Errors Occured", ExceptionsList)
Run Code Online (Sandbox Code Playgroud)

  • 这是评论而不是答案 (3认同)