[cairo] cairomm exception handling questions

Murray Cumming murrayc at murrayc.com
Mon Aug 11 10:42:05 PDT 2008


On Mon, 2008-08-11 at 09:56 -0300, Ian Britten wrote:
> Hi all,
> Just a couple of elementary exception handling questions, related
> to cairomm.  (I'm trying to get my groundwork laid correctly)
> 
> - After some trial-and-error (And grubbing through the cairomm
>    source code), I've discovered that passing an invalid file name
>    to PdfSurface::create() doesn't throw a Cairo::logic_error
>    exception, but instead, a std::ios_base::failure exception.

As you can see in the implementation here:
http://cgit.freedesktop.org/cairomm/tree/cairomm/private.cc
this is the (indirectly) recommended exception for this cairo error:
http://cairographics.org/manual/bindings-errors.html

But if we are wrong about that, changing the exceptions thrown would
generally be an API and ABI break - applications that expected the
existing exceptions would no longer work.

>    Wouldn't it make it more consistent to throw all cairomm
>    exceptions as Cairo::logic_error?  Currently, I (as a programmer
>    trying to trap all Cairo exceptions and downgrading them to
>    errors) must add multiple 'catch' statements to all my 'try'
>    statements.  That seems like it'll get repetitive/tedious pretty
>    quickly..  :(

Of course you shouldn't be catching the exceptions for every call.
That's why they are exceptions. But yes, I can see how it's a bit
annoying to have to catch more than one exception type.

I think it's more important that we document what exceptions can be
thrown by what methods. But to know that we need to know what errors can
be set by what C functions and that's lacking from the cairo
documentation currently. For instance:
http://www.cairographics.org/manual/cairo-PDF-Surfaces.html#cairo-pdf-surface-create

> - What am I expected to do with a Cairo::logic_error exception?  I
>    had been planning to try use the ErrorStatus (cairo_status_t) to
>    return a meaningful error to the calling code.  However, it seems
>    that I can't access the status (private, no 'get').

Good point. I guess there should be a get_error_code() method. A patch
would be welcome.

>   Thus, it
>    seems that all I can do is return a "Something went wrong in Cairo"
>    error, from every 'catch' that I write...
> 
> Thanks for any info, and sorry if I've missed something basic!  I'm
> just trying to make sure I get off on the right foot!
> Ian

-- 
Murray Cumming
murrayc at murrayc.com
www.murrayc.com
www.openismus.com




More information about the cairo mailing list