'Azure Synapse - How to catch SparkException

I tried below things:

import org.apache.spark.SparkException
from org.apache.spark.SparkException import SparkException
from org.apache.spark import SparkException

These all give ModuleNotFoundError: No module named 'org.apache.spark.SparkException'.

I need to handle PySpark exceptions in Azure Synapse like below:

except (Py4JJavaError, SparkException, TypeError) as e:
   print(e)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source