Graphaware neo4j-php-client | Cannot catch Neo4jEx

2019-09-09 20:40发布

问题:

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

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

回答1:

I just tested and I have no issues catching an exception, can you maybe provide more code, what is in neoconnect.php for example ?

This is my test :

$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"
 ^"⏎