简体   繁体   中英

catch (Exception ex) block misses

There are a few similar questions, but for C# mostly.

@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); 
    }

I am basically looking to catch a MySQLTimeoutException and turn it into a NotAuthorizedException (while keeping an eye for any other stuff besides TigaseDBException and UnsupportedOperationException) in the last catch block. Somehow, java eludes my master plan.

Logs show a straight

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)

As far as i can tell, the bolded line in the stack trace should have changed the exception to a NotAuthorizedException breed. What am I missing ?

Thanks

I agree. the problem is not with the code as posted. Check your assumptions. Are there other overloadings of XGateRoster.setExtraItemsDone? Try using Jad to decompile the class file you are running against. If you enable the options to show line numbers, you can be sure the (decompiled) source you are viewing is exactly the code that is executing. Do you know exactly where the log message you are looking at comes from? Maybe it comes from higher up the stack, after it is thrown but before this catch block and exception translation code are even hit.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM