473,385 Members | 1,661 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Use of STL with -fno-exceptions

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

Dec 29 '06 #1
1 4820
On Thu, 28 Dec 2006 20:32:46 -0800, krunalb wrote:
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 ;)

--
Lionel B
Dec 29 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.