def foo():
try:
do_something()
except:
raise
handle exception
def bar():
try:
foo()
except:
print 'Error occurred in foo()'
bar
将如何知道foo
引发了例外情况?
此外,如果出现以下代码的输出:
def foo():
try:
print 1/0
except Exception:
return 'Caught in foo'
try:
print 'FOOO'
print foo()
except Exception:
print 'Caught in main'
OUTPUT
:FOOO \ n抓到了foo
try:
print 'FOOO'
print foo()
except Exception:
print 'Caught in main'
def foo():
try:
print 1/0
except Exception:
return 'Caught in foo'
OUTPUT
:FOOO \ n陷入主
为什么两种情况下的输出都不同?