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
  Pynput doesn't recognize shift button and special characters VirtualDreamer 0 25 6 hours ago
Last Post: VirtualDreamer
  How to fix 'uncaught exception of type NSException' in Python MonsterPython 0 76 Jul-09-2019, 06:52 AM
Last Post: MonsterPython
  problem using custom exception handling in python srm 3 126 Jul-03-2019, 09:10 PM
Last Post: ichabod801
  'Exception Has occured: UnBoundLocalError' caston 1 131 Jun-12-2019, 02:33 PM
Last Post: perfringo
  Why doesn't my loop work correctly? (problem with a break statement) steckinreinhart619 2 212 Jun-11-2019, 10:02 AM
Last Post: steckinreinhart619
  Help with finding correct topic in Python learning yahya01 1 255 Jun-06-2019, 05:01 PM
Last Post: buran
  an easy way to disable exception handling Skaperen 6 382 Jun-02-2019, 10:38 PM
Last Post: Gribouillis
  exception name for a flagged stop Skaperen 1 495 May-31-2019, 04:33 AM
Last Post: heiner55
  name of exception for exit() Skaperen 2 193 May-24-2019, 07:07 PM
Last Post: Skaperen
  Python Script Spawned by Cron or Systemd doesn't write files..? johnnyrobot 2 177 May-24-2019, 07:04 PM
Last Post: Larz60+

Forum Jump:

Users browsing this thread: 1 Guest(s)