Dev HelpersOpen library
← Back

Chain an exception

Chain an exception. A self-contained example using the Python standard library.

Open this example in the interactive library

Source code

try:
    try:
        int('x')
    except ValueError as error:
        raise RuntimeError('Invalid input') from error
except RuntimeError as error:
    print(type(error.__cause__).__name__)

Sample output

ValueError