Fog Creek Software
Discussion Board

C++ Exceptions

Question: How do you guys usually handle different error reporting methods used by various C and C++ libraries in a C++ application?

I very much like the idea of using exceptions, but due to 1) no standard error/exception classes and 2) use of C language libraries, most applications I write tend to use something other than a standard exception: integer, strings, some odd object with no standardization.

What do you guys do with these when you're using multiple libraries all with disparate error-reporting mechanisms? I would like to have some relatively clean way to unify them, but aside from writing custom exception classes to wrap every error possibly generated by every method I call, I don't see a elegant solution out there.


Mike Swieton
Sunday, January 12, 2003

I wrestle with the same problem. What I normally try to do, is wrap calls to 3rd party APIs in my own function and "translate" their error codes (very often obscure return values or the like) to exceptions. But I only do this for "non-standard" libraries which I use only for one special problem (I work a lot with camera sdks for example).

When working with the STL or the MFC, I am rather sloppy about catching possible exceptions, since I found it very confusing to figure out which exceptions can turn up where and why. I also got the impression that when something goes wrong there, it is normally beyond repair anyway, so I catch everything in a big surrounding try/catch block and hope the program crashes more or less gracefully.

have fun,

Jutta Jordans
Monday, January 13, 2003

That's exactly what we do to. We have our own 'Error' class, with a number of descendants for different kinds of errors. All our code throws one of the descendants of 'Error'. All access to third party software is through an API which detects errors and throws an 'Error'.

Somewhere at a high level we have a big try block with

catch (Error)....



David Clayworth
Monday, January 13, 2003

I thrive on the diversity.

follow me!
Tuesday, January 14, 2003

*  Recent Topics

*  Fog Creek Home