Python Forum

Full Version: My exception doesn't work. How can I correct it?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
>>> try:
    print(1 / 0)
    except ArithmeticError:
        
SyntaxError: invalid syntax
>>>
What you are trying to accomplish?
You need to provide a body for the except branch. You can use the pass keyword if you want to ignore the excepetion.
You have to indent back if you are using IDLE,it dos not do it automatically for you.
>>> try:
       print(1 / 0)
except ArithmeticError:
    print('Can not divide by 0')

Can not divide by 0
>>>