Considering the following two program,running the program 1 will get expected output: RecursionError
program 1
===========================
import traceback
def foo():
try:
1/0
except Exception as e:
traceback.print_exc()
finally:
a = 1
foo()
foo()
==========================
-----------------------------------------------------------------------------------
ZeroDivisionError: division by zero
Traceback (most recent call last):
File "/home/xxm/Desktop/nameChanging/myerror/test1.py", line 5, in foo
1/0
ZeroDivisionError: division by zero
Traceback (most recent call last):
File "/home/xxm/Desktop/nameChanging/myerror/test1.py", line 5, in foo
1/0
ZeroDivisionError: division by zero
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/xxm/Desktop/nameChanging/myerror/test1.py", line 5, in foo
1/0
ZeroDivisionError: division by zero
Traceback (most recent call last):
File "/home/xxm/Desktop/nameChanging/myerror/test1.py", line 5, in foo
1/0
ZeroDivisionError: division by zero
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/xxm/Desktop/nameChanging/myerror/test1.py", line 12, in <module>
File "/home/xxm/Desktop/nameChanging/myerror/test1.py", line 10, in foo
foo()
File "/home/xxm/Desktop/nameChanging/myerror/test1.py", line 10, in foo
...
foo()
File "/home/xxm/Desktop/nameChanging/myerror/test1.py", line 10, in foo
foo()
File "/home/xxm/Desktop/nameChanging/myerror/test1.py", line 7, in foo
traceback.print_exc()
File "/usr/lib/python3.5/traceback.py", line 159, in print_exc
print_exception(*sys.exc_info(), limit=limit, file=file, chain=chain)
File "/usr/lib/python3.5/traceback.py", line 100, in print_exception
type(value), value, tb, limit=limit).format(chain=chain):
File "/usr/lib/python3.5/traceback.py", line 474, in __init__
capture_locals=capture_locals)
File "/usr/lib/python3.5/traceback.py", line 358, in extract
f.line
File "/usr/lib/python3.5/traceback.py", line 282, in line
self._line = linecache.getline(self.filename, self.lineno).strip()
File "/usr/lib/python3.5/linecache.py", line 16, in getline
lines = getlines(filename, module_globals)
File "/usr/lib/python3.5/linecache.py", line 43, in getlines
if len(entry) != 1:
RecursionError: maximum recursion depth exceeded in comparison
------------------------------------------------------------------------
However when moving foo() into finally clause, the interpreter crashes.
program 2
==========================
import traceback
def foo():
try:
1/0
except Exception as e:
traceback.print_exc()
finally:
a = 1
foo()
foo()
==========================
-----------------------------------------------------------------------------
File "/home/xxm/Desktop/nameChanging/myerror/test1.py", line 10 in foo
Traceback (most recent call last):
File "/home/xxm/Desktop/nameChanging/myerror/test1.py", line 5, in foo
1/0
ZeroDivisionError: division by zero
Traceback (most recent call last):
File "/home/xxm/Desktop/nameChanging/myerror/test1.py", line 5, in foo
1/0
ZeroDivisionError: division by zero
Traceback (most recent call last):
File "/home/xxm/Desktop/nameChanging/myerror/test1.py", line 5, in foo
1/0
ZeroDivisionError: division by zero
Traceback (most recent call last):
File "/home/xxm/Desktop/nameChanging/myerror/test1.py", line 5, in foo
1/0
ZeroDivisionError: division by zero
Traceback (most recent call last):
File "/home/xxm/Desktop/nameChanging/myerror/test1.py", line 5, in foo
1/0
ZeroDivisionError: division by zero
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/xxm/Desktop/nameChanging/myerror/test1.py", line 7, in foo
traceback.print_exc()
File "/usr/lib/python3.5/traceback.py", line 159, in print_exc
print_exception(*sys.exc_info(), limit=limit, file=file, chain=chain)
File "/usr/lib/python3.5/traceback.py", line 100, in print_exception
type(value), value, tb, limit=limit).format(chain=chain):
File "/usr/lib/python3.5/traceback.py", line 474, in __init__
capture_locals=capture_locals)
File "/usr/lib/python3.5/traceback.py", line 358, in extract
f.line
File "/usr/lib/python3.5/traceback.py", line 282, in line
self._line = linecache.getline(self.filename, self.lineno).strip()
File "/usr/lib/python3.5/linecache.py", line 16, in getline
lines = getlines(filename, module_globals)
File "/usr/lib/python3.5/linecache.py", line 43, in getlines
if len(entry) != 1:
RecursionError: maximum recursion depth exceeded in comparison
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/xxm/Desktop/nameChanging/myerror/test1.py", line 5, in foo
1/0
File "/home/xxm/Desktop/nameChanging/myerror/test1.py", line 10 in foo
File "/home/xxm/Desktop/nameChanging/myerror/test1.py", line 10 in foo
File "/home/xxm/Desktop/nameChanging/myerror/test1.py", line 10 in foo
...
File "/home/xxm/Desktop/nameChanging/myerror/test1.py", line 10 in foo
File "/home/xxm/Desktop/nameChanging/myerror/test1.py", line 10 in foo
...
Aborted (core dumped)
------------------------------------------------------------------------- |