Skip to content

Commit 868987e

Browse files
committed
add exception-catching function to automatically save .dump file
1 parent c8c3ae3 commit 868987e

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

pydumpling/helpers.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import sys
12
from traceback import print_tb, print_exception
3+
from .pydumpling import save_dumping
24

35

46
def print_traceback_and_except(dumpling_result):
@@ -10,3 +12,13 @@ def print_traceback_and_except(dumpling_result):
1012
print_exception(exc_type, exc_value, exc_tb)
1113
else:
1214
print_tb(exc_tb)
15+
16+
17+
def catch_any_exception():
18+
original_hook = sys.excepthook
19+
20+
def _hook(exc_type, exc_value, exc_tb):
21+
save_dumping(exc_info=(exc_type, exc_value, exc_tb))
22+
original_hook(exc_type, exc_value, exc_tb) # call sys original hook
23+
24+
sys.excepthook = original_hook

0 commit comments

Comments
 (0)