Python Forum
handling 2 exceptions at once
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
handling 2 exceptions at once
#3
(Jun-26-2020, 11:02 PM)Skaperen Wrote: i have mishandling of a case of 2 exceptions at the same time.
They are not happening at the same time the second one occurs in the handling of the first.

try:
    raise KeyboardInterrupt
except KeyboardInterrupt:
    raise BrokenPipeError
Error:
Traceback (most recent call last): File "c:/Users/Dave/Documents/VS Code WorkSpaces/pythonforum/general/forumpost2.py", line 2, in <module> raise KeyboardInterrupt KeyboardInterrupt During handling of the above exception, another exception occurred: Traceback (most recent call last): File "c:/Users/Dave/Documents/VS Code WorkSpaces/pythonforum/general/forumpost2.py", line 4, in <module> raise BrokenPipeError BrokenPipeError
put a try/except block inside the handler
try:
    raise KeyboardInterrupt
except KeyboardInterrupt:
    try:
        raise BrokenPipeError
    except BrokenPipeError:
        print('caught BrokenPipeError')
Output:
caught BrokenPipeError
Reply


Messages In This Thread
handling 2 exceptions at once - by Skaperen - Jun-26-2020, 11:02 PM
RE: handling 2 exceptions at once - by bowlofred - Jun-27-2020, 12:25 AM
RE: handling 2 exceptions at once - by Yoriz - Jun-27-2020, 08:55 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  PiCamera - print exceptions? korenron 2 835 Dec-15-2022, 10:48 PM
Last Post: Larz60+
Star python exception handling handling .... with traceback mg24 3 1,280 Nov-09-2022, 07:29 PM
Last Post: Gribouillis
  Class exceptions DPaul 1 1,297 Mar-11-2022, 09:01 AM
Last Post: Gribouillis
  is this a good way to catch exceptions? korenron 14 4,728 Jul-05-2021, 06:20 PM
Last Post: hussaind
  Python, exceptions KingKhan248 6 3,044 Nov-15-2020, 06:54 AM
Last Post: buran
  Split string between two different delimiters, with exceptions DreamingInsanity 2 2,034 Aug-24-2020, 08:23 AM
Last Post: DreamingInsanity
  remove spaces with exceptions catosp 4 2,414 May-29-2020, 09:32 AM
Last Post: catosp
  Looking for advice and Guidance on Exceptions used within Functions paul41 1 2,152 Nov-14-2019, 12:33 AM
Last Post: Larz60+
  multi-line messages in raised exceptions? Skaperen 3 7,338 Aug-01-2019, 02:17 AM
Last Post: Skaperen
  Creating custom exceptions that co-operate LadySvetlana 4 3,078 Mar-19-2019, 04:24 PM
Last Post: LadySvetlana

Forum Jump:

User Panel Messages

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