Python Forum
How to exit after a try exception?
Thread Rating:
  • 3 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to exit after a try exception?
#1
I've read so much about try and exception but none tell how to exit the program gracefully and not continue the rest of the code.  For example:

try:
    result = x / y
except ZeroDivisionError:
    print "division by zero!"
    (How do I exit the program from here?)
    (Alternatively, how do I continue the program on a different path from here?)
else:
    print "result is", result
(continue normal execution from here)
So if there is a divide by zero error, how does one exit the program from that point?
Alternatively, is there a way to jump to a different label in the program to continue execution on a different path like in Basic?

Newbie learning Python 3.6
Reply


Messages In This Thread
How to exit after a try exception? - by Raptor88 - Mar-04-2017, 01:15 AM
RE: How to exit after a try exception? - by wavic - Mar-04-2017, 04:14 AM
RE: How to exit after a try exception? - by merlem - Mar-04-2017, 08:44 AM
RE: How to exit after a try exception? - by wavic - Mar-04-2017, 09:20 PM
RE: How to exit after a try exception? - by wavic - Mar-05-2017, 08:30 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  python difference between sys.exit and exit() mg24 1 1,853 Nov-12-2022, 01:37 PM
Last Post: deanhystad
  name of exception for exit() Skaperen 2 2,413 May-24-2019, 07:07 PM
Last Post: Skaperen
  During handling of the above exception, another exception occurred Skaperen 7 26,921 Dec-21-2018, 10:58 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020