Reputation: 1145
How does one ensure that the flask error handlers get the most specific exception?
From some simple tests and looking at the source code, it looks like the flask error handling code just takes the first register error handler for a given exception type instead of the most specific type possible.
I guess the answer is to put the error handler for Exception
at the very end?
Upvotes: 4
Views: 714
Reputation: 1123740
Error handlers follow the exception class MRO, or method resolution order, and a handler is looked up in that order; the specific exception type first, then it's direct parent class, etc, all the way down to BaseException
and object
.
There is no need to order anything; if you registered a handler for Exception
, then it'd be used for any exception for which no more specific handler was found.
Upvotes: 7