RESTEasy 中的 ExceptionMapper 问题
在我的 JAXRS 应用程序中,我有 2 个 ExceptionMapper
注册为 @Provider
public class MyExceptionMapper implements ExceptionMapper<Exception> {...}
public class MyCustomRuntimeExceptionMapper implements ExceptionMapper<MyCustomRuntimeException> {...}
当我的应用程序抛出新的 MyCustomRuntimeException
时,异常会在 >MyExceptionMapper
,尽管(JAX-RS 规范规定)它应该在 MyCustomRuntimeExceptionMapper 中捕获。
JAXRS 是这样说的 -
JAX-RS 也支持异常继承。当出现异常时 抛出,JAX-RS 将首先尝试找到一个异常映射器 异常的类型。如果找不到,它将寻找映射器 可以处理异常的超类。还会继续这样的 处理直到没有更多的超类可以匹配。
有谁知道这里发生了什么事吗?
In my JAXRS application, I have 2 ExceptionMapper
registered as @Provider
public class MyExceptionMapper implements ExceptionMapper<Exception> {...}
public class MyCustomRuntimeExceptionMapper implements ExceptionMapper<MyCustomRuntimeException> {...}
When my application throws a new MyCustomRuntimeException
, the exception is caught inside the MyExceptionMapper
, even though (JAX-RS spec says) it should be caught inside MyCustomRuntimeExceptionMapper.
Here's what JAXRS says -
JAX-RS supports exception inheritance as well. When an exception is
thrown, JAX-RS will first try and find an ExceptionMapper for that
exception’s type. If it cannot find one, it will look for a mapper
that can handle the exception’s superclass. It will continue this
process until there are no more superclasses to match against.
Does anyone have a clue, whats going on here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我可以通过在我的 web.xml 中声明如下提供者来正确实现:
I am able to get it right, by declaring providers as below, in my web.xml:
我也有这个问题。看起来好像它在查找子类之前先找到了异常的超类。这使我无法使用 ExceptionMapper 来处理异常。我必须处理一个具有子类的特定于应用程序的异常;我不能为它们提供单独的异常映射器。我有一个超类的异常映射器,然后是一堆“if (e instanceof SubClassA)”语句。
I had a problem with this too. It appears as if it finds the superclass of the exception before looking for the subclass. This keeps me from having an ExceptionMapper for Exception. There's an application-specific exception I have to deal with that has subclasses; I can't have separate exception mappers for them. I have one exception mapper for the superclass and then a bunch of "if (e instanceof SubClassA)" statements.