Showing results for 
Search instead for 
Did you mean: 

Exceptions in Python driver do not extend RuntimeError

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:
        result =
        record= result.single()
        isAvailable = (record is not None) and ('online' == record['currentStatus'])
      except RuntimeError as runtimeError:
        exceptionStr = str(runtimeError)
        complaint = f"""Raised {exceptionStr}"""
  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?

Nodes 2022
NODES 2022, Neo4j Online Education Summit

On November 16 and 17 for 24 hours across all timezones, you’ll learn about best practices for beginners and experts alike.