Bottom Page

Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 My exception doesn't work. How can I correct it?
>>> try:
    print(1 / 0)
    except ArithmeticError:
SyntaxError: invalid syntax
What you are trying to accomplish?
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
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
hsunteik and micseydel like this post

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Not quite getting the correct Output from a function twinpiques 3 154 Aug-04-2019, 11:53 PM
Last Post: twinpiques
  read text file and write into html with correct link jacklee26 4 152 Aug-02-2019, 05:48 AM
Last Post: jacklee26
  Asyncio StreamReader read method doesn't respect timeout when using SSL dukadahake 0 79 Jul-24-2019, 11:55 AM
Last Post: dukadahake
  Pynput doesn't recognize shift button and special characters VirtualDreamer 0 104 Jul-17-2019, 11:55 AM
Last Post: VirtualDreamer
  How to fix 'uncaught exception of type NSException' in Python MonsterPython 0 116 Jul-09-2019, 06:52 AM
Last Post: MonsterPython
  problem using custom exception handling in python srm 3 176 Jul-03-2019, 09:10 PM
Last Post: ichabod801
  'Exception Has occured: UnBoundLocalError' caston 1 164 Jun-12-2019, 02:33 PM
Last Post: perfringo
  Why doesn't my loop work correctly? (problem with a break statement) steckinreinhart619 2 247 Jun-11-2019, 10:02 AM
Last Post: steckinreinhart619
  Help with finding correct topic in Python learning yahya01 1 281 Jun-06-2019, 05:01 PM
Last Post: buran
  an easy way to disable exception handling Skaperen 6 423 Jun-02-2019, 10:38 PM
Last Post: Gribouillis

Forum Jump:

Users browsing this thread: 1 Guest(s)