@JonB said in Error handling (Linux, Qt 5.15):
If you really feel this strongly about the way Delphi/CBuilder handles this (which btw only started out as checking for a null pointer,
Look as an Access Violation handling can be realized withing a function (Linux QTcreator). My example looks not very pleasant but QT developers probably can make macros to make it look good. Yes, in the business of handling first were logjumps, then try/catch followed.
jmp_buf ape;
void AcessViolationHandler(int signum)
{
_ML.p("AcessViolationHandler is called"); //this is my logger
// Do stuff here then return to execution below
longjmp(ape, 1);
}
//------------------
void Tmq_blf::on_actionAccess_Violation_tst_triggered()
{
struct sigaction act;
struct sigaction oldact;
memset(&act, 0, sizeof(act));
act.sa_handler = AcessViolationHandler;
act.sa_flags = SA_NODEFER | SA_NOMASK;
sigaction(SIGSEGV, &act, &oldact);
int i = 10, *j=NULL;
if (0 == setjmp(ape))
{
*j = i;
sigaction(SIGSEGV, &oldact, &act);
} else {
sigaction(SIGSEGV, &oldact, &act);
/* handle SIGSEGV */
}
QMessageBox bx; bx.setText("The app survived AccessViolation and continue to run"); bx.exec();
}
//------------------