How do you reraise an exception in Python?

Experience Level: Junior
Tags: Python

Answer

Use the try/except block and raise statement.

def do_reraise_exception():

    try:
        int('Not a number')
    except ValueError:
        print("A value error was intercepted")
        raise

Python for beginners
Python for beginners

Are you learning Python ? Try our test we designed to help you progress faster.

Test yourself