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?
#7
(Dec-16-2019, 11:08 PM)Skaperen Wrote: i have tried nothing, yet. unless i can come up with a good test the covers all possible cases, i don't bother to waste my time trying it. for this, my concern is whether a direct raise might, for some exceptions, be handled different because it is in a try clause. a test for that would need to try every possible exception. it is impractical to do a test like that, so i did not try. but if you have a way to do it, i am interested. a file listing every possible exception might be usable as i could build a code sequence from that

i already know how to raise an exception and how to handle one. i do not know if anything different is done in an explicit raise inside a try clause that, while trying to optimize certain behavior, might end up making certain exceptions behave slightly different.

Sorry that you don't want to waste your time. I wouldn't expect anyone else to, either, given that it's your code.
That aside, There is no difference in handling a raised exception regardless of where it is raised. You should be able to determine every type of exception that your code can possible throw by examining each action that you take. For instance casting data types can throw a TypeError, the use of lists can produce an IndexOutOfBoundsException, Using dictionaries can produce a KeyError. However, you should not need to go through every possible type of exception.
Once you have accounted for each type of exception make an except to deal with it. Another user in the thread correctly suggested using a more exotic error type, which makes a lot of sense.
Give it a shot, it's not too difficult.
When you've got something post it if it doesn't work the way that you expect. I'm sure many here will help fix errors once there is code on which to work.
Reply


Messages In This Thread
RE: can i raise an exception in a try clause? - by Clunk_Head - Dec-17-2019, 05:43 AM

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