builder.branch(goodLabel); builder.exceptionHandler(tryStart, tryEnd, ClassCastException.class.getName());
/** * @param sequenceVar if non-null, calls OrderedInvoker.finished. */ private void genExceptionHandler(CodeBuilder b, Label tryStart, Label tryEnd, LocalVariable sequenceVar) { b.exceptionHandler(tryStart, tryEnd, Throwable.class.getName()); if (sequenceVar != null) { TypeDesc orderedInvokerType = TypeDesc.forClass(OrderedInvoker.class); b.loadThis(); b.loadField(ORDERED_INVOKER_FIELD_NAME, orderedInvokerType); b.loadLocal(sequenceVar); b.invokeVirtual(orderedInvokerType, "finished", null, new TypeDesc[] {TypeDesc.INT}); } }
/** * * @param opType type of operation, Insert, Update, or Delete */ private void addExitTransaction(CodeBuilder b, String opType, LocalVariable txnVar, Label tryStart) { if (tryStart == null) { addExitTransaction(b, opType, txnVar); return; } // } catch (... e) { // txn.exit(); // throw e; // } Label tryEnd = b.createLabel().setLocation(); b.exceptionHandler(tryStart, tryEnd, null); addExitTransaction(b, opType, txnVar); b.throwObject(); }
/** * * @param opType type of operation, Insert, Update, or Delete */ private void addExitTransaction(CodeBuilder b, String opType, LocalVariable txnVar, Label tryStart) { if (tryStart == null) { addExitTransaction(b, opType, txnVar); return; } // } catch (... e) { // txn.exit(); // throw e; // } Label tryEnd = b.createLabel().setLocation(); b.exceptionHandler(tryStart, tryEnd, null); addExitTransaction(b, opType, txnVar); b.throwObject(); }
b.branch(contLabel); b.exceptionHandler(tryAfterCon, endFinallyLabel, null); yieldConnection(b, capVar, conVar); b.throwObject(); b.exceptionHandler (tryBeforeCon, b.createLabel().setLocation(), RuntimeException.class.getName()); b.throwObject(); b.exceptionHandler (tryBeforeCon, b.createLabel().setLocation(), Exception.class.getName()); b.loadLocal(capVar);
b.branch(contLabel); b.exceptionHandler(tryAfterCon, endFinallyLabel, null); yieldConnection(b, capVar, conVar); b.throwObject(); b.exceptionHandler (tryBeforeCon, b.createLabel().setLocation(), RuntimeException.class.getName()); b.throwObject(); b.exceptionHandler (tryBeforeCon, b.createLabel().setLocation(), Exception.class.getName()); b.loadLocal(capVar);
/** * Generates code which emulates this: * * ... * } finally { * JDBCConnectionCapability.yieldConnection(con); * } * * @param capVar required reference to JDBCConnectionCapability * @param conVar optional connection variable * @param tryAfterCon label right after connection acquisition */ private void yieldCon (CodeBuilder b, LocalVariable capVar, LocalVariable conVar, Label tryAfterCon) { Label endFinallyLabel = b.createLabel().setLocation(); Label contLabel = b.createLabel(); yieldConnection(b, capVar, conVar); b.branch(contLabel); b.exceptionHandler(tryAfterCon, endFinallyLabel, null); yieldConnection(b, capVar, conVar); b.throwObject(); contLabel.setLocation(); }
/** * Generates code which emulates this: * * ... * } finally { * JDBCConnectionCapability.yieldConnection(con); * } * * @param capVar required reference to JDBCConnectionCapability * @param conVar optional connection variable * @param tryAfterCon label right after connection acquisition */ private void yieldCon (CodeBuilder b, LocalVariable capVar, LocalVariable conVar, Label tryAfterCon) { Label endFinallyLabel = b.createLabel().setLocation(); Label contLabel = b.createLabel(); yieldConnection(b, capVar, conVar); b.branch(contLabel); b.exceptionHandler(tryAfterCon, endFinallyLabel, null); yieldConnection(b, capVar, conVar); b.throwObject(); contLabel.setLocation(); }
/** * Assumes a boolean is on the stack, as returned by doTryInsert or doTryUpdate. */ private void addNormalizationRollback(CodeBuilder b, Label doTryStart, List<PropertyCopy> unnormalized) { if (unnormalized == null) { return; } Label doTryEnd = b.createLabel().setLocation(); b.dup(); Label success = b.createLabel(); b.ifZeroComparisonBranch(success, "!="); for (int i=0; i<2; i++) { if (i == 0) { } else { b.exceptionHandler(doTryStart, doTryEnd, null); } // Rollback normalized properties. for (PropertyCopy copy : unnormalized) { copy.restore(b); } if (i == 0) { b.branch(success); } else { b.throwObject(); } } success.setLocation(); }
/** * Assumes a boolean is on the stack, as returned by doTryInsert or doTryUpdate. */ private void addNormalizationRollback(CodeBuilder b, Label doTryStart, List<PropertyCopy> unnormalized) { if (unnormalized == null) { return; } Label doTryEnd = b.createLabel().setLocation(); b.dup(); Label success = b.createLabel(); b.ifZeroComparisonBranch(success, "!="); for (int i=0; i<2; i++) { if (i == 0) { } else { b.exceptionHandler(doTryStart, doTryEnd, null); } // Rollback normalized properties. for (PropertyCopy copy : unnormalized) { copy.restore(b); } if (i == 0) { b.branch(success); } else { b.throwObject(); } } success.setLocation(); }
/** * Generates code that loads a Storage instance on the stack, throwing a * FetchException if Storage request fails. * * @param type type of Storage to request */ private void loadStorageForFetch(CodeBuilder b, TypeDesc type) { b.loadThis(); b.loadField(SUPPORT_FIELD_NAME, mSupportType); TypeDesc storageType = TypeDesc.forClass(Storage.class); TypeDesc repositoryType = TypeDesc.forClass(Repository.class); b.invokeInterface (mSupportType, "getRootRepository", repositoryType, null); b.loadConstant(type); // This may throw a RepositoryException. Label tryStart = b.createLabel().setLocation(); b.invokeInterface(repositoryType, STORAGE_FOR_METHOD_NAME, storageType, new TypeDesc[]{TypeDesc.forClass(Class.class)}); Label tryEnd = b.createLabel().setLocation(); Label noException = b.createLabel(); b.branch(noException); b.exceptionHandler(tryStart, tryEnd, RepositoryException.class.getName()); b.invokeVirtual (RepositoryException.class.getName(), "toFetchException", TypeDesc.forClass(FetchException.class), null); b.throwObject(); noException.setLocation(); }
/** * Generates code that loads a Storage instance on the stack, throwing a * FetchException if Storage request fails. * * @param type type of Storage to request */ private void loadStorageForFetch(CodeBuilder b, TypeDesc type) { b.loadThis(); b.loadField(SUPPORT_FIELD_NAME, mSupportType); TypeDesc storageType = TypeDesc.forClass(Storage.class); TypeDesc repositoryType = TypeDesc.forClass(Repository.class); b.invokeInterface (mSupportType, "getRootRepository", repositoryType, null); b.loadConstant(type); // This may throw a RepositoryException. Label tryStart = b.createLabel().setLocation(); b.invokeInterface(repositoryType, STORAGE_FOR_METHOD_NAME, storageType, new TypeDesc[]{TypeDesc.forClass(Class.class)}); Label tryEnd = b.createLabel().setLocation(); Label noException = b.createLabel(); b.branch(noException); b.exceptionHandler(tryStart, tryEnd, RepositoryException.class.getName()); b.invokeVirtual (RepositoryException.class.getName(), "toFetchException", TypeDesc.forClass(FetchException.class), null); b.throwObject(); noException.setLocation(); }
/** * Generates code which emulates this: * * ... * } finally { * rs.close(); * } * * @param rsVar ResultSet variable * @param tryAfterRs label right after ResultSet acquisition */ private void closeResultSet (CodeBuilder b, LocalVariable rsVar, Label tryAfterRs) { Label contLabel = b.createLabel(); Label endFinallyLabel = b.createLabel().setLocation(); b.loadLocal(rsVar); b.invokeInterface(TypeDesc.forClass(ResultSet.class), "close", null, null); b.branch(contLabel); b.exceptionHandler(tryAfterRs, endFinallyLabel, null); b.loadLocal(rsVar); b.invokeInterface(TypeDesc.forClass(ResultSet.class), "close", null, null); b.throwObject(); contLabel.setLocation(); }
/** * Generates code which emulates this: * * ... * } finally { * statement.close(); * } * * @param statementVar Statement variable * @param tryAfterStatement label right after Statement acquisition */ private void closeStatement (CodeBuilder b, LocalVariable statementVar, Label tryAfterStatement) { Label contLabel = b.createLabel(); Label endFinallyLabel = b.createLabel().setLocation(); b.loadLocal(statementVar); b.invokeInterface(TypeDesc.forClass(Statement.class), "close", null, null); b.branch(contLabel); b.exceptionHandler(tryAfterStatement, endFinallyLabel, null); b.loadLocal(statementVar); b.invokeInterface(TypeDesc.forClass(Statement.class), "close", null, null); b.throwObject(); contLabel.setLocation(); }
/** * Generates code which emulates this: * * ... * } finally { * rs.close(); * } * * @param rsVar ResultSet variable * @param tryAfterRs label right after ResultSet acquisition */ private void closeResultSet (CodeBuilder b, LocalVariable rsVar, Label tryAfterRs) { Label contLabel = b.createLabel(); Label endFinallyLabel = b.createLabel().setLocation(); b.loadLocal(rsVar); b.invokeInterface(TypeDesc.forClass(ResultSet.class), "close", null, null); b.branch(contLabel); b.exceptionHandler(tryAfterRs, endFinallyLabel, null); b.loadLocal(rsVar); b.invokeInterface(TypeDesc.forClass(ResultSet.class), "close", null, null); b.throwObject(); contLabel.setLocation(); }
/** * Generates code which emulates this: * * ... * } finally { * statement.close(); * } * * @param statementVar Statement variable * @param tryAfterStatement label right after Statement acquisition */ private void closeStatement (CodeBuilder b, LocalVariable statementVar, Label tryAfterStatement) { Label contLabel = b.createLabel(); Label endFinallyLabel = b.createLabel().setLocation(); b.loadLocal(statementVar); b.invokeInterface(TypeDesc.forClass(Statement.class), "close", null, null); b.branch(contLabel); b.exceptionHandler(tryAfterStatement, endFinallyLabel, null); b.loadLocal(statementVar); b.invokeInterface(TypeDesc.forClass(Statement.class), "close", null, null); b.throwObject(); contLabel.setLocation(); }
builder.branch(goodLabel); builder.exceptionHandler(tryStart, tryEnd, ClassCastException.class.getName());
Label cont = b.createLabel(); b.branch(cont); b.exceptionHandler(tryStart, tryEnd, Throwable.class.getName()); b.invokeStatic(UNCAUGHT_METHOD_NAME, null, new TypeDesc[] {TypeDesc.forClass(Throwable.class)});
Label cont = b.createLabel(); b.branch(cont); b.exceptionHandler(tryStart, tryEnd, Throwable.class.getName()); b.invokeStatic(UNCAUGHT_METHOD_NAME, null, new TypeDesc[] {TypeDesc.forClass(Throwable.class)});
b.exceptionHandler(tryStartDecode, tryEndDecode, CorruptEncodingException.class.getName()); TypeDesc exType = TypeDesc.forClass(CorruptEncodingException.class);