builtins.TypeError: catching classes that do not inherit from BaseException is not allowed

hongy...@gmail.com hongyi.zhao at gmail.com
Thu Dec 30 17:32:51 EST 2021


On Thursday, December 30, 2021 at 11:23:35 PM UTC+8, Chris Angelico wrote:
> If it's an exception, it needs to subclass Exception or BaseException. 

I see. That is, the following:

class TailRecurseException(Exception):
  def __init__(self, args, kwargs):
    self.args = args
    self.kwargs = kwargs

 
> (Also, is this REALLY an optimization? Exception handling isn't the 
> fastest. Yes, it avoids some measure of recursion depth, but it looks 
> like a pretty inefficient way to do things. Python is not Lisp, and 
> there are very very few algorithms that actually benefit from tail 
> call optimization that wouldn't benefit far more from other ways of 
> doing the same thing.) 

Could you give some examples of the other methods you mentioned above?
 
> ChrisA

HZ


More information about the Python-list mailing list