cURL / Mailing Lists / curl-library / Single Mail


RE: can you throw exceptions from curl callbacks

From: Peter Walker <>
Date: Tue, 10 Feb 2009 09:08:52 -0000

Normal C library. Ah, makes sense :)

Peter Walker
Senior Developer
Ticketmaster UK
48 Leicester Square
London WC2H 7LR
T: +44 (0) 207 022 8547
F: +44 (0) 207 915 0411
M: +44 (0) 7855 441471
This e-mail is private and confidential and may contain proprietary or
legally privileged information. It is for the intended recipient only.
If you have received this e-mail in error, please notify the author by
replying to it and then destroy it. If you are not the intended
recipient you must not use, disclose, distribute, copy, print or rely on
this e-mail or any attachment.
Thank You!

-----Original Message-----
[] On Behalf Of Phil Blundell
Sent: 09 February 2009 22:19
To: libcurl development
Subject: Re: can you throw exceptions from curl callbacks

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.

Received on 2009-02-10