Skip to content Skip to sidebar Skip to footer

Nested Causes In Nested Exceptions In Python

Is there a way to provide information about the cause of an inner exception when passing it up the chain (like it's possible in java with the cause property of Exception class). P

Solution 1:

In Python 3, you can use the from keyword to specify an inner exception:

raise ClientException(...) from ioException

You get a traceback that looks like this:

Traceback (most recent call last):
  ...
IOException: timeout

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  ...
ClientException: couldn't read from client

Post a Comment for "Nested Causes In Nested Exceptions In Python"