Re: exception from C function?
"George" <George@discussions.microsoft.com> wrote in message
news:03CBCB84-5AD0-4B19-8D0E-D1B72EDC287B@microsoft.com
As far as I know, C function does not throw exception.
But Bjarne said in his book, section 14.8 Exception and Efficiency,
--------------------
In particular, an implementation knows that only a few standard C
library functions (such as atexit() and qsort()) can throw
exceptions, and it can take advantage of that fact to generate better
code. --------------------
What did he mean? C function could really throw exception?
qsort takes a pointer to a callback the programmer provides. The
callback may throw an exception. qsort will let this exception propagate
out to its caller.
bsearch is another standard C library function to which this
consideration applies.
I'm not sure why Stroustroup mentions atexit here. atexit does take a
callback pointer, but doesn't call it right away. Instead, it is called
during program termination. If the callback throws at that time, the
program is aborted immediately by calling terminate(). In any case,
atexit() itself can't throw, as far as I can tell.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925