pdf-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [pdf-devel] Error module: first lines


From: Behdad Esfahbod
Subject: Re: [pdf-devel] Error module: first lines
Date: Sun, 16 Dec 2007 16:54:14 -0500

On Fri, 2007-12-14 at 18:30 -0300, address@hidden wrote:
> 
> Well, I have written a few lines. For now I'm just following the
> lib/error.h API.
> 
> Also, We could define a maximum of errors and abort in case it's
> exceeded.
> 
> Also, I'm not sure if "pdf_error_one_per_line" will be of use.
> 
> Suggestions are welcome, as always :-)

Are you proposing these as part of the error handling scheme for the
library?  If yes, I'm strongly against them.  Libraries should:

  - Be re-entrant.  That means, a global total-number-of-errors is
useless.

  - Not write anything on stdout/stderr unless explicitly asked to.
(this can be relaxed to "Not write anything... if explicitly asked to",
but I prefer the former)

  - Not terminate the process unless explicitly asked to.  That means,
no abort on bad input.  No asserts as much as possible.  Debug builds
are an exception.

  - Be painlessly usable by multiple users in the same process.  That
means, things like "context" objects should be used that encapsulate
everything a user of the library needs, and allow for multiple contexts
to co-exists.  This essentially requires all the above, no global
total-number-of-errors, no unwanted printout, and definitely no
termination.


I highly recommend the error-reporting scheme used in cairo.  The way it
works is that each object retains its own error status (the error code
of the first encountered error in fact) and ignores any subsequent
requests to the object.  Errors are propagated from object to object,
and can be queried for by the user.  This lends itself quite well to
language bindings that want to throw exceptions for example, and is
comfortable to use from C too, as you can simply draw whatever you want
(make as many function calls as you want) and only query for error at
the end.


My 2 cents :)

-- 
behdad
http://behdad.org/

...very few phenomena can pull someone out of Deep Hack Mode, with two
noted exceptions: being struck by lightning, or worse, your *computer*
being struck by lightning.  -- Matt Welsh





reply via email to

[Prev in Thread] Current Thread [Next in Thread]