-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhelpers.py
28 lines (21 loc) · 993 Bytes
/
helpers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import sys
import traceback
class Exceptions():
@staticmethod
def print_exception(e):
#"Printing only the traceback above the current stack frame"
error_msg = ''.join(traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2]))
#"Printing the full traceback as if we had not caught it here..."
error_msg += Exceptions.format_exception(e)
return error_msg
@staticmethod
def format_exception(e):
exception_list = traceback.format_stack()
exception_list = exception_list[:-2]
exception_list.extend(traceback.format_tb(sys.exc_info()[2]))
exception_list.extend(traceback.format_exception_only(sys.exc_info()[0], sys.exc_info()[1]))
exception_str = "Traceback (most recent call last):\n"
exception_str += "".join(exception_list)
# Removing the last \n
exception_str = exception_str[:-1]
return exception_str