_sqldf value in case of query failure in %sql cell

pjain
New Contributor II

I am trying to write a code for Error Handling in Databricks notebook in case of a SQL magic cell failure. I have a %sql cell followed by some python code in next cells. I want to abort the notebook if the query in %sql cell fails. To do so I am looking at the value of _sqldf variable. I am aware that the temporary variable holds the sql results when the query is successful however I couldn't find How the magic cell will behave in case of let say SQL Server connection failure. I want to stop the execution of complete notebook in case SQL magic cell fails. As the sql REPL cannot handle the python's code, I cannot throw the exception using try/except in the same %sql cell.
Am I thinking in the right direction or is there any other way to handle the failure?