Re: Bjarne's comments about exception specification
* Erik WikstrFm:
On 2008-01-20 11:26, Alf P. Steinbach wrote:
* George2:
Hello everyone,
How do you understand the Bjarne's comments about exception
specification? Especially, "not required to be checked across
compilation-unit" and "violations will not be caught at run time"?
section 14.6.1 Checking Exception Specifications
--------------------
Importantly, exception-specifications are not required to be checked
exactly across compilation-unit boundaries. Naturally, an
implementation could check. However, for many large and long-lived
systems, it is important that the implementation does not -- or, if it
does, than it carefully gives hard errors only where violations will
not be caught at run time.
--------------------
I wonder where you found that and how old it is.
If it refers to C++ then it's incorrect per the current standard (1998),
and was also incorrect with respect to the 1991 ARM.
It is in the 3rd ed. of TC++PL, but it is taken out of context. I think
he is referring to whether the compiler will give any warnings/errors at
compile-time (though I can not find any mentioning of this in the standard).
The standard is quite clear about compile checking.
For certain constructs (overriding a virtual function, assigning or
initializing a function pointer) exception specifications are
effectively required to be checked at compile time.
But in the general case of checking whether a function implementation
violates the function's exception specification, the 98 standard sayeth:
?15.4/10
"An implementation shall not reject an expression merely because when
executed it throws or might throw an exception that the containing
function does not allow"
Following up with an example of a well-formed function (must compile)
that has a stronger exception specification than a function it calls.
In other words, the standard effectively specifies that the code must
compile regardless of what a function's implementation might or
logically must throw; however, a compiler is free to emit diagnostics
(which would in practice be warnings) just as with other constructs.
So I can't make heads or tails of the "checked /exactly/" (emphasis
added) in the quoted passage, with the interpretation of compile time
checking, because with that interpretation they're in general not
required to be checked at all, much less "exactly". Perhaps the OP
could do the honors of checking the TCPPPL errata pages and see whether
this has been reworded.
Section 14.6.1 starts by talking about checking of exception-
specifications at compile-time and the paragraph after the quoted one
says that the point is that you should not have to go through all your
code and update your exception-specifications just because you make some
change that allows more exceptions to be thrown.
Yep, and that's what the standard's ?15.4/10 is all about.
Cheers,
- Alf
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?