[Development] Exceptions

Henry Skoglund henry at tungware.se
Tue May 7 23:15:41 CEST 2024


On 2024-05-07 21:05, Turtle Creek Software wrote:
> TurtleSoft posted on the Interest list earlier about problems we had 
> with exception handling, and Thiago suggested I post here.
>
> Since the early 90s, our C++ code has had about 10,000 sanity checks 
> which give an error message with source file & line number, then throw 
> an exception. There is a try/catch block in the event loop which 
> swallows them.  That way users can continue work.  Only a small % of 
> the checks are ever called, but it makes bugs very easy to fix when 
> users or testers report them. Our app almost never crashes thanks to 
> the many checks. We learned the system from Bill Atkinson, author of 
> MacPaint and HyperCard.
>
> The sanity system started in Metrowerks PowerPlant, then worked OK in 
> Carbon, Cocoa, and MFC.  For Qt we wrapped QApplication::notify with 
> try/catch. It worked for most checks on Macintel and Wintel, but 
> failed for Mac ARM. After the message, instant termination. Users lose 
> their work, testers must start over.
>
> Turns out that Qt intentionally does not support exceptions thrown 
> through GUI classes, and the early success was just an accident.
>
> Exceptions are an "exceptionally" handy C++ feature. Instant "beam me 
> up, Scotty". It is too bad that Qt does not support them fully, and 
> I'd like to change that. So I would be willing to work on getting GUI 
> classes like QWidget able to pass exceptions, if it means we can get 
> our old sanity-checking back. It would be our open-source contribution.
>
> I realize this is a huge, fundamental change to Qt. It would need to 
> be a multi-year project, done in tiny bits so as not to break things.  
> Anyhow, my time is limited.
>
> Getting exceptions through signals/slots is lower priority. We don't 
> use those much and probably could bypass them somehow. We just want a 
> reliable path to the event loop.
>
> Personally, I've programmed since punch card days in 1966 or so. I've 
> designed and shipped several apps for PCs. I've refactored and rebuilt 
> all sorts of C++ code from other people, and could do this work 
> politely and competently.
>
> Does this seem reasonable?
>
> Dennis Kolva
> Programming Director
> TurtleSoft.com
>
>

Hi, interesting idea! However such a fundamental replumbing of Qt might 
be a Herculean task.
I assume you've already looked a QException? It's a part of Qt 
Concurrent and requires extra, receiving thread for the catching so it 
might not fit the bill.

Maybe instead of using vanilla throws and catches, try implementing a 
qThrow function that uses std::basic_stacktrace 
https://en.cppreference.com/w/cpp/utility/basic_stacktrace to do your 
own portable, generic stack unwinding?

Just some thoughts :-) Rgrds Henry



More information about the Development mailing list