On 28/06/2017 11:05, Markus Armbruster wrote:
> If foo() additionally returned an indication of success, you could write
> 
>       if (!foo(arg, errp)) {    // assuming foo() returns a bool
>           handle the error...
>       }
> 
> Nicely concise.
> 
> For what it's worth, this is how GLib wants GError to be used.  We
> deviated from it, and it has turned out to be a self-inflicted wound.
> 

I find Eduardo's proposal better.  With GLib's way it's easy to confuse
functions that return 0/-1, 0/-errno, TRUE/FALSE, FALSE/TRUE or
NULL/non-NULL.

Declaring and testing local_err doesn't introduce much boilerplate, it's
propagation to errp that does.  The disadvantage of Eduardo's mechanism
is that it produces slightly worse code, but Error** is rarely used in
hot code.  It could also be improved slightly by changing
ignored_error_unset and ignored_error_set to a 2-element array.

Paolo

Reply via email to