问题描述
我正在为我的项目使用Postgresql + Neo4j.如果neo4j查询失败,我需要回滚postgres查询.因此,我需要在代码中捕获Neo4jException.但是还不能完成.感谢您的帮助.
I'm using Postgresql + Neo4j for my project. I need to rollback postgres queries if neo4j query has failed. So, I need to catch Neo4jException in my code. But couldn't done yet. Thanks for help.
require_once('pgconnect.php');
try{
$conn->beginTransaction();
//some pgsql code
$conn->commit();
require_once('neoconnect.php');
$result = $client->run("a query");
$conn = null;
}
catch(PDOException $e){
require_once('pgrollback.php');
}
这是我的工作代码.但是如您所见,我没有catch块可以捕获neo4j异常.所以我加了这个,但是没有运气.还尝试使用Neo4jExceptionInterface作为异常类(绝望的时间). (顺便说一句,我正在使用错误的类型查询来获取异常)
this is my working code. But as you can see I don't have a catch block to catch neo4j exception. So I added this but no luck. also tried withNeo4jExceptionInterface as exception class (desperate times). (BTW I'm using wrong typed query to get exception)
catch(Neo4jException $ex){
//done smth
}
也尝试这样做而没有运气.
Also tried to do this without luck too.
$client->run("a query") or throw new Neo4jException();
推荐答案
我刚刚进行了测试,没有遇到异常的问题,您能否提供更多代码,例如neoconnect.php
中的内容?
I just tested and I have no issues catching an exception, can you maybe provide more code, what is in neoconnect.php
for example ?
这是我的测试:
$client = ClientBuilder::create()
->addConnection('default', 'http://localhost:7474')
->build();
$query = 'INVALID QUERY';
try {
$result = $client->run($query);
} catch (\GraphAware\Neo4j\Client\Exception\Neo4jException $e) {
echo sprintf('Catched exception, message is "%s"', $e->getMessage());
}
-
ikwattro@graphaware ~/d/g/p/neo4j-php-client> php test.php
Catched exception, message is "Invalid input 'I': expected <init> (line 1, column 1 (offset: 0))
"INVALID QUERY"
^"⏎
这篇关于Graphaware neo4j-php-client |无法捕获Neo4jException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!