Python Forum
best way to force an exception
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
best way to force an exception
#2
I would assume you'd just raise the exception that you want to catch.

debug = True
try:
    # run the exception
    if debug:
        raise ZeroDivisionError
except ZeroDivisionError:
    print("Got division error without actually dividing")

print("all done")
Reply


Messages In This Thread
best way to force an exception - by Skaperen - Oct-20-2020, 11:57 PM
RE: best way to force an exception - by bowlofred - Oct-21-2020, 12:15 AM
RE: best way to force an exception - by Gribouillis - Oct-21-2020, 05:59 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  force a program to exit ? Armandito 3 2,813 May-12-2022, 04:03 PM
Last Post: Gribouillis
  Force calculation result as decimal vercetty92 4 3,025 Mar-20-2019, 02:27 PM
Last Post: vercetty92
  During handling of the above exception, another exception occurred Skaperen 7 27,242 Dec-21-2018, 10:58 AM
Last Post: Gribouillis
  Password Brute Force 2skywalkers 9 5,701 Oct-18-2018, 02:35 PM
Last Post: buran
  Brute Force Password Guesser 2skywalkers 1 3,327 Oct-05-2018, 08:04 PM
Last Post: ichabod801
  Brute Force Pad Lock Guesser RedSkeleton007 4 4,166 Mar-03-2018, 07:42 AM
Last Post: RedSkeleton007
  brute force password from list petru 10 12,388 Apr-04-2017, 02:08 PM
Last Post: buran

Forum Jump:

User Panel Messages

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