gpt4 book ai didi

c# - 如何立即抛出 List 异常

转载 作者:太空宇宙 更新时间:2023-11-03 22:57:19 25 4
gpt4 key购买 nike

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

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

throw new AggregateException("Multiple Errors Occured", ExceptionsList)

此外,

List<CustomExceptionObject> ThrowException(List<CustomExceptionObject> ExceptionList)
{
AggregateException eggExp = new AggregateException(ExceptionList);
throw new eggExp;
}

我使用这些方法不断收到未处理的异常错误。感谢任何见解。

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

An exception of type 'System.AggregateException' occurred in XYZ.dll but was not handled in user code.

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

最佳答案

聚合异常是抛出作为异常集合的异常的正确方法。

throw new AggregateException("Multiple Errors Occured", ExceptionsList)

关于c# - 如何立即抛出 List<CustomExceptionObj> 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44780076/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com