Python Forum
My exception doesn't work. How can I correct it? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/Forum-Python-Coding)
+--- Forum: General Coding Help (https://python-forum.io/Forum-General-Coding-Help)
+--- Thread: My exception doesn't work. How can I correct it? (/Thread-My-exception-doesn-t-work-How-can-I-correct-it)



My exception doesn't work. How can I correct it? - Ponomarenko Pavlo - Dec-19-2016

>>> try:
    print(1 / 0)
    except ArithmeticError:
        
SyntaxError: invalid syntax
>>>


RE: My exception doesn't work. How can I correct it? - wavic - Dec-19-2016

What you are trying to accomplish?


RE: My exception doesn't work. How can I correct it? - micseydel - Dec-19-2016

You need to provide a body for the except branch. You can use the pass keyword if you want to ignore the excepetion.


RE: My exception doesn't work. How can I correct it? - snippsat - Dec-19-2016

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
>>>