cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

Error handling/exception handling in NOtebook

KuldeepChitraka
New Contributor III

What is a common practice to to write notebook which includes error handling/exception handling.

Is there any example which depicts how notebook should be written to include error handling etc.

4 REPLIES 4

Ajay-Pandey
Esteemed Contributor III

Hi @Kuldeep Chitrakar​ you can use try and catch to handle the exception

Ajay Kumar Pandey

ramravi
Contributor II

 it's just a simple try except  code, something like this:

results = {}
 
were_errors = False
 
for script_name in ['script1', 'script2', 'script3']:
 
  try:    
 
    retValue = dbutils.notebook.run(script_name)
 
    results[script_name] = retValue
 
  except Exception as e:
 
    results[script_name] = "Error: {e}"
 
    were_errors = True
 
 
 
if were_errors:
 
  log failure # you can use data from results variable
 
else:
 
  log success

Aviral-Bhardwaj
Esteemed Contributor III

use try catch

AviralBhardwaj

Meghala
Valued Contributor II

runtime looks for handlers (try-catch) that are registered to handle such exceptions

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group