Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Neo4j:异常处理和解释调用failure()/close()?_Neo4j - Fatal编程技术网

Neo4j:异常处理和解释调用failure()/close()?

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(); //

我正在尝试处理Neo4Jtry事务中的异常

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) {
    // ..
}