Throwing an AggregateException in my own code

前端 未结 2 1444
小蘑菇
小蘑菇 2021-02-18 20:24

How should I go about collecting exceptions and putting them into an AggregateException to re-throw?

For my specific code, I have a loop and will have zero or more excep

2条回答
  •  爱一瞬间的悲伤
    2021-02-18 20:32

    The simplest way would be to add the exceptions to a List until you were ready to throw the AggregateException.

    It seems strange to me that you would want to return the old exceptions the next time you create an AggregateException, but if you kept your List around, you could just build a new AggregateException from this.

提交回复
热议问题