cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Exceptions in Python driver do not extend RuntimeError

tms
Graph Buddy

My understanding of Python is that user-defined exceptions are supposed to extend the built-in RuntimeError class.

Here's some code that I expect to work:

def isAvailableDatabase_(self, aDatabaseName):
  cypherQuery = f"""SHOW DATABASE `{aDatabaseName}` YIELD currentStatus"""
  with self.neo4JAdapterPreset() as adapter:
    with adapter.sessionWithParameters_(database='system') as session:
      try:
        result = session.run(cypherQuery)
        record= result.single()
        isAvailable = (record is not None) and ('online' == record['currentStatus'])
      except RuntimeError as runtimeError:
        exceptionStr = str(runtimeError)
        complaint = f"""Raised {exceptionStr}"""
        print(complaint)
  return False

I want this method to simply return False when the database isn't available, such as while Neo4J is not running. The stuff inside the exception handler is just so that I can see what's happening.

I want truly awful and unexpected exceptions to NOT be caught. I don't want to "leak" the Neo4J-specific exceptions from the official Python driver into this code.

Is there a straightforward way to catch an ancestor of the several exceptions defined in the official Python driver for Neo4J?

0 REPLIES 0
Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

All the sessions of the conference are now available online