Python Forum
can i raise an exception in a try clause?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
can i raise an exception in a try clause?
#11
there are these two kinds of exceptions: those that "happen" and those that are explicitly raised. the latter probably covers most everything because implementations have to decide the case for exceptions.

there are these two kinds of exceptions: those that are explicitly raised in a try clause and those that happen somewhere else as a result of what is being done in a try clause. the compiler, perhaps when optimizing, could shortcut the explicit raise because it sees a match between the exception being raised and that exception being one that is handled right there.

try:
    if foo:
        raise bar()
    duh(1)
except bar:
    duh(2)
that would be a long way to decide how to call duh(). maybe the compiler might try to optimize it and do:
duh(1 if foo else 2)
would that change have an impact? i don't really know. that's why i'm asking.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Messages In This Thread
RE: can i raise an exception in a try clause? - by Skaperen - Dec-17-2019, 07:27 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to use the LIKE clause in Python Columbo 9 1,655 Oct-09-2022, 10:22 PM
Last Post: Larz60+
  SQL Query is not executing WHERE clause hammer 7 2,355 Nov-15-2021, 01:44 PM
Last Post: hammer
  How does this if clause work? Pedroski55 3 2,296 Jun-10-2021, 06:31 AM
Last Post: Gribouillis
  raise exception within generator bermudj 3 2,992 Jun-06-2020, 11:56 AM
Last Post: buran
  pass captured value from input() to where clause metro17 5 3,284 Sep-09-2019, 05:24 AM
Last Post: metro17
  Changing a traceback message without a 2nd raise Clunk_Head 1 1,994 Jul-14-2019, 12:45 AM
Last Post: Gribouillis
  finally clause Skaperen 6 3,890 Jun-02-2019, 09:02 PM
Last Post: snippsat
  if clause fails DeadCthulhuWaitsDreaming 10 4,796 Apr-07-2019, 09:19 PM
Last Post: DeadCthulhuWaitsDreaming
  how to code in Python "where" clause of SAS FelixS 2 2,809 Mar-26-2019, 04:59 PM
Last Post: FelixS
  During handling of the above exception, another exception occurred Skaperen 7 26,932 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