I have a simple question with a likely more complicated answer.
I wrote a custom Exception class in Python:
class MyError(Exception):
def __init__(self, message, other_info):
Exception.__init__(self, message)
self.other_info = other_info
What I would like to do is alter the default handling of this exception to include the information in other_info, but I want to keep it out of the main Exception message for organization's sake.
I have seen a post on how to override sys.excepthook entirely, but I don't want to change how it works -- I just want to change the way MyError is handled. Is this possible?
__str__method of the exception? Other than the type, which you can match in anexceptclause, the exception handling system doesn't really deal with the internal details of an exception object. Those details are for use by the particular handling code when you catch a specific exception.