Python: Make exception info concept local

This commit is contained in:
Rasmus Lerchedahl Petersen
2021-03-03 16:47:31 +01:00
parent 4196dc2291
commit f02a19669f
12 changed files with 88 additions and 140 deletions

View File

@@ -0,0 +1,15 @@
import sys, traceback
try:
1/0
except:
exc_type, exc_value, exc_traceback = sys.exc_info() #$ exceptionInfo
tb = traceback.extract_tb(exc_traceback) #$ exceptionInfo
stack = traceback.extract_stack() #$ exceptionInfo
print(traceback.format_exc(1, tb)) #$ exceptionInfo
print(traceback.format_exception(exc_type, exc_value, exc_traceback)) #$ exceptionInfo
print(traceback.format_exception_only(None, exc_value)) #$ exceptionInfo
print(traceback.format_list(stack)) #$ exceptionInfo
print(traceback.format_stack()) #$ exceptionInfo
print(traceback.format_tb(exc_traceback)) #$ exceptionInfo