Failed assertion throws runtime_error; message box moved to GUI main loop try..catch wrapper (#496)
Failed assertions were not properly handled in extant code. We launched a QMessageBox
from a thread, which is unsafe according to the Qt docs, and actually failed (it could be repaired by shortening the error message, e.g. by ommitting the file name, but that would be quite fragile a solution).
Now, a failed assertion just throws a std::runtime_error
. We don't use qFatal
any longer. This allows us to remove the failedAssert
function pointer and the QMessageHandler
.
If catched inside the GUI, the failed assertion is displayed in the message frame. Otherwise, the exception is catched in the main
program, which launches a QMessageBox
within a fresh QApplication
.
This leaves one specific case uncovered, namely: Failed assertions (and other exceptions) thrown in event handlers but outside specific try
blocks.
Merge request reports
Activity
requested review from @m.svechnikov
- Resolved by Wuttke, Joachim
-
Exception from
ASSERT
can (and will) be caught before it reaches the top of the hierarchy, then it is likely to be handled as any other user-produced exception, program will not be terminated. -
Try, for example,
ASSERT(0)
in
-
ISimulation::runSingleSimulation
(inside and outside of std::thread) ISimulation::subscribe
JobWorker::start
IOFactory::writeDatafield
It will just terminate the program.
-
added 7 commits
-
20fc397f...71ebb013 - 3 commits from branch
r20.0
- d61225bb - Failed assertion throws runtime_error; message box moved to GUI main loop try..catch wrapper
- 3266c782 - corr include
- e1e87906 - use QApplication instance; set return values
- 78632f91 - debugging
Toggle commit list-
20fc397f...71ebb013 - 3 commits from branch
added 5 commits
- 9090b8d7 - GUI JobWorker: extend 'try' coverage; rm special treatment for impossible case of no m_simulation
- 6839c4d2 - Failed assertion throws runtime_error; message box moved to GUI main loop try..catch wrapper
- 9fc767c5 - corr include
- 32db9452 - use QApplication instance; set return values
- b702719c - debugging
Toggle commit listadded 8 commits
-
b702719c...3fff6fd4 - 4 commits from branch
r20.0
- d76cbec6 - Failed assertion throws runtime_error; message box moved to GUI main loop try..catch wrapper
- 6e3201d4 - corr include
- b091a789 - use QApplication instance; set return values
- 79a3dec6 - Failed assert also writes to stderr. Extended try block in main.cpp. MsgBox...
Toggle commit list-
b702719c...3fff6fd4 - 4 commits from branch
added 1 commit
- ac95af06 - Extend message on failed assertion: 'BUG:', 'Please report ...'
enabled an automatic merge when the pipeline for ac95af06 succeeds
mentioned in commit ce832e20
mentioned in issue libqcr#7 (closed)