Why is PanicException
derived from BaseException
?
#2638
-
The docs state that PanicException derives from BaseException so that it makes the interpreter exit. But regular I think it'd be better to derive from In particular, I'm running into issues with a Python fuzz testing library that (rightly) assumes something has gone wrong beyond a test failure when a generic |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
There is an explanation in the docstring: "Like SystemExit, this exception is derived from BaseException so that it will typically propagate all the way through the stack and cause the Python interpreter to exit." This follows the philosophy that panics are not on the same level as exceptions in languages that have them, but something more "severe" that usually leads to an abort if no extraordinary measures are taken ( It's funny, your link to the hypothesis source shows that pytest defines its own exceptions derived from BaseException. As you can see from that, there is no such universal rule as "all user defined exceptions must derive Exception". |
Beta Was this translation helpful? Give feedback.
There is an explanation in the docstring: "Like SystemExit, this exception is derived from BaseException so that it will typically propagate all the way through the stack and cause the Python interpreter to exit." This follows the philosophy that panics are not on the same level as exceptions in languages that have them, but something more "severe" that usually leads to an abort if no extraordinary measures are taken (
catch_panic
andexcept BaseException
).It's funny, your link to the hypothesis source shows that pytest defines its own exceptions derived from BaseException. As you can see from that, there is no such universal rule as "all user defined exceptions must derive Exception".