Best way to check whether a certain exception type was the cause (of a cause, etc …) in a nested exception?

后端 未结 8 1273
误落风尘
误落风尘 2021-02-03 21:05

I am writing some JUnit tests that verify that an exception of type MyCustomException is thrown. However, this exception is wrapped in other exceptions a number of

8条回答
  •  野性不改
    2021-02-03 21:20

    I don't think you have any choice but to call through the layers of getCause. If you look at the source code for the Spring NestedRuntimeException that you mention that is how it is implemented.

提交回复
热议问题