-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patherror_handler.py
More file actions
28 lines (24 loc) · 1018 Bytes
/
error_handler.py
File metadata and controls
28 lines (24 loc) · 1018 Bytes
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 logging
logger = logging.getLogger('ErrorHandler')
import traceback
import sys
from PyQt5.QtWidgets import QMessageBox
def error_handler(exception, context=None, messagebox=True):
print(traceback.format_exc(), file=sys.stderr, flush=True)
if context is None:
context = '(unspecified)'
if messagebox:
msgbox = QMessageBox()
msgbox.setText(
f'The following error occurred while trying to perform the operation \"{context}\":<br />'
f'<pre>{str(exception)}</pre><br />'
f'See the terminal output for traceback and other information'
)
msgbox.exec()
else: # Display on console
silent_error_handler(exception=exception, context=context)
def silent_error_handler(exception, context=None):
logger.error('An exception occurred while trying to perform the operation \"{}\"'.format(
context if context is not None else '(unspecified)'
))
print(traceback.format_exc(), file=sys.stderr, flush=True)