| 1 |
Exception reporting in QBzr |
| 2 |
*************************** |
| 3 |
Overview |
| 4 |
======== |
| 5 |
QBzr has a global exception handler. This will either report the exception |
| 6 |
to the command line, or show a dialog with the error. The behaviour of this |
| 7 |
can be modified to suit the area of the program. |
| 8 |
|
| 9 |
Modes |
| 10 |
===== |
| 11 |
There are 3 different modes for the exception reporting: (In the code, these |
| 12 |
are called "type") |
| 13 |
|
| 14 |
|
| 15 |
MAIN_LOAD_METHOD |
| 16 |
---------------- |
| 17 |
The behaviour of this mode depends on whether the window is in ui_mode or not. |
| 18 |
If in ui_mode, the window is closed, and the report is written to the console. |
| 19 |
If not in ui mode, the report is displayed in a dialog. This dialog only has |
| 20 |
one button - "Close", which closes both this dialog, and the window. |
| 21 |
|
| 22 |
This mode should be used for initial window loading methods, where if the method |
| 23 |
fail, then the dialog would be useless, and hence gets closed every time. |
| 24 |
|
| 25 |
SUB_LOAD_METHOD |
| 26 |
--------------- |
| 27 |
The behaviour of this mode is to show the report in a dialog, with just a close |
| 28 |
button. When the close button is clicked, the report dialog is closed, but not |
| 29 |
the window. |
| 30 |
|
| 31 |
The mode should be used for methods where you are executing an action, or |
| 32 |
loading data from user input provided in the gui, e.g. when you open a branch, |
| 33 |
and the location is from a text edit. In these cases, you need to tell the user |
| 34 |
that there was an error, but allow the user to continue working. |
| 35 |
|
| 36 |
ITEM_OR_EVENT_METHOD |
| 37 |
-------------------- |
| 38 |
The behaviour of this mode is to show the report in a dialog, with just a close |
| 39 |
and a ignore button. When the close button is clicked, the report dialog and the |
| 40 |
window are closed. If the ignore button is pressed, just the report dialog is |
| 41 |
closed. |
| 42 |
|
| 43 |
If no mode it specified by the method below, then the global exception handler |
| 44 |
uses this as the default, and hence covers alot of unexpected errors. It gives |
| 45 |
the user the option to ignore a minor error, and continue working. |
| 46 |
|
| 47 |
Controlling the mode |
| 48 |
==================== |
| 49 |
You can either decorate your method with @reports_exception, which wraps your |
| 50 |
method in a try..except for every time is is called. Or you can have your own |
| 51 |
try..except, and call report_exception in the except. Both of these except a |
| 52 |
type parameter, with MAIN_LOAD_METHOD as the default. |
| 53 |
|
| 54 |
E.g.:: |
| 55 |
|
| 56 |
@reports_exception() |
| 57 |
def load(self): |
| 58 |
|
| 59 |
@reports_exception(type=SUB_LOAD_METHOD) |
| 60 |
def refresh(self): |
| 61 |
|
| 62 |
try: |
| 63 |
self.tree.add(paths) |
| 64 |
except Exception: |
| 65 |
report_exception(type=SUB_LOAD_METHOD, window=self.window()) |