Search code examples
pythonpython-2.7conditional-statementsstack-overflow

Use overflow error as condition in Python?


I need to use an overflow error in Python as a condition. I.E. if the overflow error occurs then perform function b, rather than simply halting the program.

I can't find the right keywords to google if this is possible, can anyone point me in the right direction?


Solution

  • Just use a try/except block:

    try:
        raise OverflowError("Uuuups")
    except OverflowError as e:
        do_some_stuff(e)
    

    Here you have a live example