[Qt-interest] error handling patterns with regard to (qt) gui programming

Jason H scorp1us at yahoo.com
Tue Jul 19 19:32:19 CEST 2011


I've done both error codes and exceptions.

I don't like exceptions as they are often used to display code or call stacks. Also, they make debugging harder when you find yourself in the catch {}. But checkign every error result is tedious.

Really, if you structure your code to use layered try catch blocks, you'll have something that can handle a reasonable number of things gracefully. Lets say your are running some long export and your database connection goes away. 

Your dialog's  Accept function should have its own try catch, your export should have its own try catch and whatever is handling the data i/o should have a try catch around that. You'll be reasonably protected that way.

But never display a dialog from library code. Let the GUI do that. If you put it in the library, then everywhere you use the library you will need a GUI (limiting the reuse of your library) and also require a user to be present to respond to the error. 


In a "well structured" GUI, the GUI only actuates the business logic via a controller class. It should not matter if the business logic is executing over a socket or natively. One day it might be one, and on another day, the other. The GUI only provides one of many possible views. 


But whether you are going return code checking or exception type checking, it does not really matter.




________________________________
From: Matthias Dahl <ml_qt-interest at binary-island.eu>
To: qt-interest at qt.nokia.com
Sent: Tuesday, July 19, 2011 1:13 PM
Subject: [Qt-interest] error handling patterns with regard to (qt) gui programming

Hello everyone.

Coming from a more server/client related background where I had to write tools,
clients and servers (with some very nice detours to graphics programming), I've
just recently made the serious step up to gui programming and I've been  asking
myself ever since if any good design patterns exist for  error  handling within
a gui program.

I've read mostly that one should prefer lower level error handling because that
is where most informations about the error are available. Yet I find it hard to
open a QErrorMessage in some GUI unrelated part of the code where for example a
database connection is handled.

Throwing exceptions is naturally partly a way out. But imho exceptions are only
for serious or fatal problems and not a general solution. That and there's also
the possible performance impact and the usual (design) pitfalls.

So I'd like to ask how you guys handle errors in your own programs?   Are there
any commonalities or patterns you follow? Or maybe some tips?

Thanks a lot in advance for the input...

So long,
matthias    
_______________________________________________
Qt-interest mailing list
Qt-interest at qt.nokia.com
http://lists.qt.nokia.com/mailman/listinfo/qt-interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110719/6380bf24/attachment.html 


More information about the Qt-interest-old mailing list