Jersey
documentation解释了如何将Exception
转换为Response
,但未能详细说明如果我的代码抛出Exception
会发生什么没有映射或派生自WebApplicationException
。
如果映射器没有处理抛出的异常,它将由JAX-RS在其中运行的容器(即servlet)传播和处理。
但这只解释了JAX-RS 2.0
应该如何按照一般术语行事,而不是Jersey
如何在这种情况下container
来处理这个Exception
}。
我知道有些人会说Well, why don't you try it out and see what happens?
...答案是:Because I like to know the documentation and I try to avoid empirical results, since they can be contaminated with coincidences and exceptional cases
。
所以,问题是:
Jersey
如何处理未映射的Exceptions
,如SQLException
或IllegalArgumentException
?由Exceptions
之一引发但未由我的代码处理的Resources
。
答案 0 :(得分:2)
泽西岛总是部署在某个地方。通常,它是一个servlet容器(例如在应用程序服务器或Tomcat中),但在仅Java SE环境中,它可以是例如Grizzly甚至是JDK HTTP server。有关部署选项,请参阅documentation。
Jersey的未捕获(或抛出)异常会对此部署环境产生影响。例如,servlet容器通常捕获Exception,记录它并返回http状态500。