cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: can you throw exceptions from curl callbacks

From: Phil Blundell <pb_at_reciva.com>
Date: Mon, 09 Feb 2009 22:19:28 +0000

On Mon, 2009-02-09 at 16:38 +0000, Peter Walker wrote:
> I just noticed that I am generating errors in the curl easy callbacks
> (the write header callback) due to inappropriate headers from a
> webservice I am communicating with. The error detection which is
> working, writes an error to a log and also throws an exception yet the
> application is not catching these errors.
>
> Instead an ABORT signal is being raised.
>
> Is this the norm, meaning i cannot use exceptions in the callback
> functions?

Yes, this is the norm. Libcurl is a plain C library and it doesn't know
anything about exceptions. In general you can't throw through a
non-exception-aware caller since this might deny it the chance to do
necessary cleanups before it gets unthreaded.

In any case, from an API point of view it probably doesn't make a lot of
sense to throw from a libcurl callback. Where are you expecting to
catch these exceptions? From the calling application's point of view it
seems like you would end up seeing essentially-arbitrary exceptions
coming out of curl_multi_perform and the like, and it isn't obvious to
me what you would usefully do with them at that point.

p.
Received on 2009-02-09