Neo4j:异常处理和解释调用failure()/close()?
我正在尝试处理Neo4Jtry事务中的异常Neo4j:异常处理和解释调用failure()/close()?,neo4j,Neo4j,我正在尝试处理Neo4Jtry事务中的异常 try(Transaction tx = graphDb.beginTx()) { // more code tx.sucess(); } 我发布的代码是标准的,它将事务保存在变量tx中,在try块tx结束时,将自动调用close() 如何处理这种类型的块中的异常?我知道以下工作: Transaction tx = graphDb.beginTx(); try{ // more code tx.sucess(); //
try(Transaction tx = graphDb.beginTx()) {
// more code
tx.sucess();
}
我发布的代码是标准的,它将事务保存在变量tx
中,在try块tx结束时,将自动调用close()
如何处理这种类型的块中的异常?我知道以下工作:
Transaction tx = graphDb.beginTx();
try{
// more code
tx.sucess(); // must always be called like so
} catch(Exception e) {
tx.failure(); // as an exception arised, would be best to call this.
} finally {
tx.close(); // is tx.close called automatically, or must I call it like I did here?
}
所以我有两个问题,第一个代码示例:如何处理其中的异常?
第二个代码示例:我必须显式调用什么以及自动调用什么?只需添加异常处理,但忽略最后一个:
try(Transaction tx = graphDb.beginTx()) {
// more code
tx.sucess();
} catch(Exception e) {
// ..
}