Skip to content

Why is PanicException derived from BaseException ? #2638

Answered by birkenfeld
rhaps0dy asked this question in Questions
Discussion options

You must be logged in to vote

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 and except 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".

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@rhaps0dy
Comment options

Answer selected by rhaps0dy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants