【发布时间】:2015-03-25 03:58:00
【问题描述】:
我在 try-catch 中有一些代码,在该代码中我正在调用 web 服务。在 web 服务上我设置了超时。
我有两个 Web 服务调用,一个不花时间,它工作正常,另一个花很长时间响应问题不是这样,而是因为超时,它应该抛出 SocketTimeoutException,但它抛出 PrivilegedActionException,并且在一个长堆栈状态之后它的显示原因通过 SocketTimeoutException。
我故意让服务调用时间非常短以获取 SocketTimeoutException,但它给了我 PrivilegedActionException 作为主要异常。
我想捕获 SocketTimeoutException,但我无法捕获 PrivilegedActionException,因为在代码级别它显示的 PrivilegedActionException 没有被这个 try catch 抛出。
我已经编写了下面的代码来实现我的目标,但它不起作用
try {
//some code here for service call
}catch(SocketTimeoutException e)
{
//not able to come here even though cause of the PrivilegedActionException is SocketTimeoutException
}
catch(Exception e)
{
//directly coming here OF COURSE
}
堆栈跟踪:
java.security.PrivilegedActionException: com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Message send failed
com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: java.security.PrivilegedActionException: com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Message send failed
【问题讨论】:
-
在第一个 catch 块中尝试
SocketTimeoutException | PrivilegedActionException吗?阅读更多Java find the first cause of an exception -
仅针对其他查看者,我使用的是 java 1.6 .....不支持此功能....
标签: java exception-handling socket-timeout-exception