I've function to calculate data and after successful calculation the mail has been send to user. but now I want to do error mapping for user interface to show error to users, so that they understand where exactly the error is getting, In their data or in my system.
So I'm Trying below Code:
def calculateFleet():
try:
# some file running code
try:
# Code For Calculation
Except Exception as E:
Print(E)
raise Exception from E
# sendEmail(user,E) # Send email if calculation successful
Except Exception as E:
print(E)
# sendEmail(user,E) # Send email if any error occured
I want to throw the one exception to another exception. like given in an image:
How can I pass/raise/throw an exception to another exception?
Thanks In advance!!
As you are using raise Exception from E
, then the "outer" exception will have the "inner" exception as its __cause__
attribute. The following
try:
try:
raise Exception("foo")
except Exception as e:
raise Exception("bar") from e
except Exception as e:
print("outer", e)
print("inner", e.__cause__)
outputs
outer bar
inner foo