In my RESTEasy application I'm getting a java.lang.reflect.UndeclaredThrowableException
, because a checked exception is being thrown from a method that doesn't declare the exception in the throws clause.
So I'm writing an UndeclaredThrowableExceptionMapper
. The UndeclaredThrowableException
wraps the real exception; I call e.getCause()
to retrieve it.
Can I then throw it or somehow look up the proper ExceptionMapper
to handle it?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You can try adding a @Context javax.ws.rs.ext.Providers
field/property to your UndeclaredThrowableExceptionMapper
class.
Then use Providers.getExceptionMapper(Class)
to look up the real exception mapper you want to use.