I have the following custom exception class I created:
class MyException(Exception):
def __init__(self, message):
self.message = message
super().__init__(self.message)
def __str__(self):
return f"MyException error -> {self.message}"
My goal is to only show the exception message, not the full traceback. For example:
try:
int('a')
except ValueError:
raise MyException("Incorrect value")
should output only MyException: MyException error -> Incorrect value
This result can be achieved with sys.tracebacklimit = 0
, however, I want to apply this only to my custom exception class.
Moreover, I don't want to use print statements to output exception message.
Any help will be appreciated.