(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