0

Am new to databricks . I have a notebook that has multiple commands . I want to capture the specific error message that is thrown when any of the commands fail. basically I would want to customize the error message in order to be able to identify which command of the notebook failed or caused the failure . In my Notebook each command performs a specific task and I want to know which task failed . How or what should I include to capture the error details ?

Currently we are just setting a generic error message when the notebook activity failed , but we are trying to find a mechanism that would give us more info on which command in the notebook failed that caused the notebook activity to fail

  • 1
    The python error traceback message will contain the exact line of code where the error occurred. Surely that is specific enough? – John Gordon Aug 02 '23 at 19:27

1 Answers1

0

You can use traceback module to store the error as suggested by @John Gordon in comments.

Use below code and keep your code in try block.

import traceback

#Variable for the error
a=''
try:
    ...Your code...
except:
    # Store the error in variable
    a=traceback.format_exc()
print(a)

Example:

enter image description here

This will give the exact information about the error and error line in your code.

You can also store your error in a file with traceback.print_exc(file=fileObject).

Rakesh Govindula
  • 5,257
  • 1
  • 2
  • 11