3 ms·
A large number of libraries already do this: glib uses GError, and glibmm wraps it in a very similar fashion. It's also worth mentioning that it's pretty easy
by awalton 12y ago
A large number of libraries already do this: glib uses GError, and glibmm wraps it in a very similar fashion.
It's also worth mentioning that it's pretty easy to create the Error object on the stack, such than an error_free() function isn't necessary, but strings become a bit more messy in that case (like needing string interning or forcing all error strings to be static).
- apaprocki 12y agoCame to mention GError as well. I actually use the GError implementation/style to auto-bind GObject based classes to Spidermonkey JS exceptions in a homegrown generic JS binding layer (not unlike GObjectIntrospection, which came about much later). When everyone uses this style it doesn't really get in the way, even when used from C, and prevents cases where APIs don't return proper error info. Everyone just gets used to putting the error parameter last. (And code generators are especially good at it :))