[Qt5-feedback] new Qt5 - great! - but: What about exceptions?

Thiago Macieira thiago at kde.org
Tue May 17 12:32:57 CEST 2011


On Tuesday, 17 de May de 2011 11:34:30 Frans Klaver wrote:
> Errors should be handled there where your business logic knows how to
> handle them. That is true for both error codes and exceptions. The pro
> for exceptions is that you don't clutter your lower level business
> logic with a lot of error checking, the con is that C++ exceptions are
> messy at best.

The downside of doing that is that sometimes the exception travels too many 
layers, to the point where the business logic has no clue what to do with the 
error.

Suppose your business logic is about creating a widget. Suddenly you get an 
exception about file not found, because the widget creates a database viewer, 
which opens a connection to a database, which is read from a file. What are you 
going to do with that "file not found" error? More importantly, what happens if 
this is a new exception, because the database driver was updated and the old 
one was memory-only?

No, errors need to be caught where they make sense. The database driver needs 
to catch the "file not found" error and transform it in an error of its own; 
the database viewer probably will react my swallowing the error, changing to 
an invalid state and showing an empty view.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Senior Product Manager - Nokia, Qt Development Frameworks
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt.nokia.com/pipermail/qt5-feedback/attachments/20110517/d3bffc25/attachment.bin 


More information about the Qt5-feedback mailing list