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