Use of STL with -fno-exceptions

K

krunalb

Hi,

As I understand STL are bound to throw an exception on occurrence of
invalid condition.
Is there a way in which I can use -fno-exceptions with STL. (Something
similar to new(nothrow)

Regards,
Krunal
 
L

Lionel B

Hi,

As I understand STL are bound to throw an exception on occurrence of
invalid condition.
Is there a way in which I can use -fno-exceptions with STL. (Something
similar to new(nothrow)

(This is somewhat OT since -fno-exceptions is compiler-specific...)

There is nothing stopping you using -fno-exceptions with STL code. STL
calls will still throw exceptions, but you will not be able to catch them
yourself (code will not compile) - instead a default exception handler
kicks in on a throw which just prints out the exception ands aborts the
program. If you're happy with this go ahead and use it, although the
only reason I can think of for doing so might be a (quite likely
insignificant) increase in program speed/size, since the compiler
presumably doesn't have to generate stack-unwinding information.

As for the nothrow version of new there is AFAIK no general mechanism for
"suppressing" exceptions - I don't see that this would make sense,
really... if a condition occurs that triggers an exception, you surely
don't want to ignore it; so either you give up and bail out (as
-fno-exceptions effectively enforces), or you'd want to test for the
exceptional condition - as you (should) do, for example, after calling
new(nothrow). This implies that the library would have to provide some
alternative means of checking for exceptional conditions for _every_
call that could throw; something, perhaps, like the standard C library's
"errno"... but hang on a minute, C++ has a better mechanism for handling
this - it's called exceptions ;)
 

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,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top