[sane-devel] Using C++ in sane backends
povilas at radix.lt
Sun May 19 18:32:30 BST 2019
On 2019-05-16 14:29, Olaf Meeuwissen wrote:
>>> Please be aware that your backend will have to catch *all* exceptions,
>>> even the ones you don't throw yourself, e.g. an `std::bad_alloc`. Any
>>> uncaught exception will crash SANE frontends right then and there with
>>> no chance of saving state.
>> Agreed. My plan was to catch all exceptions, print something to logs and
>> then return some error status code so that everything works just like if
>> the C implementation got an error it couldn't recover from. The caller
>> code should be completely isolated from what happens within the backend.
> Good plan but might be harder than you think. I had the same plan way
> back when I wrote that utsushi SANE backend and learnt the hard way.
> Especially the exception that was thrown *before* its sane_init() was
> even called had me bang my head against the wall for a while.
Were those exceptions caused by constructors of static objects by
chance? In our case we have full control of the backend, so we can avoid
static initialization completely if we want.
More information about the sane-devel