any exception causing code, e.g.
l= [1,2,3]
index = 4
l[index]
produce standard exception output to console
trace
IndexError: list index out of range
Process finished with exit code 1
I'd like to add custom message at the bottom
trace
IndexError: list index out of range
My own message here (i.e. better explained what have happened)
Process finished with exit code 1
I tried numerous options but I'm not able to get desired output. I'd be fine with raising new exception from original one as in
try:
l= [1,2,3]
index = 4
l[index]
except Exception as e:
MyException = (create new exception that on raise produce only single line message)
raise MyException from e
however new exception displays lots of noise like its own trace, and I only seem to be able to get rid of it via sys.tracebacklimit = 0
what hides original exception trace as well - not desired.
I neither was able to override original error's __ str __ and or __ repr __ to inject my message to the end (note adding new entry into error.args won't do the trick since at best do smt like
IndexError: My own message, rest of original output (i.e. error.args)
what is not what I want. I want to show very last line (likely first thing the user will read) a simple business message, and only whoever is interested can go into the details above it. Real use case is there is workflow manager what runs steps (code outside of my control) and I want to display any exception as is thrown by the step, only appending some text to the bottom (i.e. above exception occurred while workflow manager was trying to do flow X, running step Y)