catch(Exception ex)阻止未命中

时间:2012-05-26 23:14:15

标签: java exception-handling

有一些类似的问题,但主要针对C#。

@Override
public void setExtraItemsDone(XMPPResourceConnection session) throws NotAuthorizedException 
{
    try
    {
        cp1 = Calendar.getInstance().getTimeInMillis();

        try 
        {
             ...

        } catch (TigaseDBException e) {

                         ...

        } catch (UnsupportedOperationException e) {

                         ...
        }


    } catch (Exception e) {

        cp2 = Calendar.getInstance().getTimeInMillis();
        throw new NotAuthorizedException(e.getMessage() + "; method took " + (cp2 - cp1) + " ms", e); 
    }

我基本上希望捕获一个MySQLTimeoutException,并在最后一个catch块中将其转换为NotAuthorizedException(同时密切关注除TigaseDBException和UnsupportedOperationException之外的任何其他内容)。不知何故,java逃避了我的总体规划。

日志显示直接

com.mysql.jdbc.exceptions.MySQLTimeoutException: Statement cancelled due to timeout or client request
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1754)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2019)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1937)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1922)
at tigase.db.jdbc.JDBCRepository.addDataList(JDBCRepository.java:183)
at tigase.db.jdbc.JDBCRepository.setDataList(JDBCRepository.java:1175)
at tigase.db.UserRepositoryMDImpl.setDataList(UserRepositoryMDImpl.java:651)
at tigase.xmpp.RepositoryAccess.setDataList(RepositoryAccess.java:1152)
at tigase.xmpp.RepositoryAccess.setOfflineDataList(RepositoryAccess.java:1204)
**at tigase.xmpp.impl.XGateRoster.setExtraItemsDone(XGateRoster.java:370)**
at tigase.xmpp.impl.DynamicRoster.setExtraItemsDone(DynamicRoster.java:377)
at tigase.xmpp.impl.JabberIqRoster.dynamicSetRequest(JabberIqRoster.java:178)
at tigase.xmpp.impl.JabberIqRoster.process(JabberIqRoster.java:329)
at tigase.server.xmppsession.SessionManager$ProcessorWorkerThread.process(SessionManager.java:2135)
at tigase.util.WorkerThread.run(WorkerThread.java:132)

据我所知,堆栈跟踪中的粗体线应该已将异常更改为NotAuthorizedException品种。我错过了什么?

由于

1 个答案:

答案 0 :(得分:0)

我同意。问题不在于发布的代码。检查你的假设。是否存在XGateRoster.setExtraItemsDone的其他重载?尝试使用Jad反编译您正在运行的类文件。如果启用选项以显示行号,则可以确保您正在查看的(反编译)源正是正在执行的代码。您是否确切知道您正在查看的日志消息来自哪里?也许它来自堆栈中的更高层,在它被抛出之后但是在这个catch块和异常转换代码被击中之前。