exception from C function?

G

George2

Hello everyone,


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? What
exception -- C++ exception or structured exception?


thanks in advance,
George
 
T

Thomas J. Gritzan

George2 said:
As far as I know, C function does not throw exception.

But Bjarne said in his book, section 14.8 Exception and Efficiency,

There are no structured exceptions in C++ world (it's a MS Windows specific
thing), so Bjarne meant C++ exceptions.

atexit() and qsort() both take function pointers to callback function that
get called at some time and these functions could throw an exception. So
atexit() and qsort() can indirectly throw exceptions.
 
J

James Kanze

George2 said:
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? What
exception -- C++ exception or structured exception?

qsort() (and bsearch()) call a function through a pointer,
passed in as an argument. The function they call might throw an
exception, which will then (normally) propagate through the
library function out to user code. (Although atexit() also
takes a pointer to a function, I rather doubt that it can raise
an exception, since it doesn't call that function during its
execution.)
 
J

James Kanze

There are no structured exceptions in C++ world (it's a MS
Windows specific thing), so Bjarne meant C++ exceptions.
atexit() and qsort() both take function pointers to callback
function that get called at some time and these functions
could throw an exception. So atexit() and qsort() can
indirectly throw exceptions.

I wouldn't be so sure about atexit(). It's pretty much
guaranteed that the function you pass to it won't be called
until after atexit() returns. (Threading issues aside, but if
you're calling exit() in one thread, and atexit() in another,
you've got real problems in your code.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top