I want to know if there would be a way to catch exceptions inside called methods.
Example:
def foo(value):
print value
foo(x)
This would throw a NameError exception, because x is not declared.
I’d like to catch this NameError exception inside foo method.
Is there a way?
Not exactly, but there is a way to catch every exception that isn’t handled:
Unfortunately,
sys.excepthookis only called “just before the program exits,” so you can’t return control to your program, much less insert the exception intofoo().