Python: Maximum recursion depth exceeded when printing custom exception
The following code throws RuntimeError: maximum recursion depth exceeded while getting the str of an object . I can resolve the infinite recursion in two different ways, but I don't understand why each fix works and thus don't know which to use, or if either are correct. class FileError( Exception ): def __init__( self, filename=None, *a, **k ): #Fix 1: remove super super( FileError, self ).__init__( self, *a, **k ) self.filename = filename def __repr__( self ): return "<{0} ({1})>".format( self.__class__.__name__, self.filename ) #Fix 2: explicitly define __str__ #__str__ = __repr__ print(