Re: throwable .vs. non throwable?
On Jul 24, 4:18 pm, Jerry Coffin <jcof...@taeus.com> wrote:
In article <46a5b550.1661...@news.utanet.at>, rpbg...@yahoo.com says...
[ ... ]
You misunderstood exception specifications in C++. In general,
templates and exception specifications don't blend.
Exception specifictions don't blend with coding in general,
even without templates. My advice, at least, is to not use
exception specifications at all, ever.
A few people point out that (at least in theory) an empty
exception specification can allow better optimization of some
code under some circumstances. IMO, this isn't sufficient to
justify their use, but there are some who consider this
sufficient justification for using empty exception
specifications.
In addition to my other comments, it just occurs to me that
there is one (admittedly very special) case where they are
almost necessary. If you write a placement operator new
function which returns a null pointer if it cannot fulfill the
request, you must give it an empty exception specification.
Without an empty exception specification, the compiler is free
to assume that the function will never return a null pointer,
and generate code like:
T* tmp = ::operator new( sizeof T ) ;
tmp->constructor() ;
If the operator new function has an empty exception
specification, it is required to generate something like:
T* tmp = ::operator new( sizeof T ) ;
if ( tmp != NULL ) {
tmp->constructor() ;
}
As I said, it's a very special case, but it's one case where you
don't have a choice.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34