Ioannis said:
void somefunc(void) throw()
"Error: void somefunc(void) throw(): Wrong exception specification.
somefunc can throw std::bad_alloc, std::range_error".
That is make the compiler to check exception specifications
for errors too.
As i know, folks time by time offer the idea. The checking is
possible, of course, but will reqiure changes of many properties of C+
+ exception handling paradigm, maybe properties of C++ core.
Unfortunately, there are many useful changes if C++, that can not be
resolved by std library, so all of the ideas go away
.
For your "void somefunc(void) throw()" declaration.
In the example, you are using declaration of "throw(type)" as logical
one, to tell programmers about expected types of exception. And
compiler, or course, easy can do compile tests according declarations
of all used function, as compiler do it for all parameters.
In the case of exception "Warning:" can be used instead of "Error:".
But you can guess, that exception handling require runtime overhead in
comparison with ordinary C-style function, but some function never
will throw, so they could be implemented without the overhead.
The C++ declaration "throw()" do the same - define the kind of
function implementation rather than declare logical type of
exception.
The overhead is the fact, that implementation of exception handling
_logically_ require from function _two_ separated returns - with
exception and without. The requirement _logically_ means, that
external context must pass to the function two addresses: ordinary
return point and exceptional return point.
But if the C-style function "somefunc throw()" does throw, the
exception can not be passed via boundaries of "somefunc", due to
absence of the _logically_ second return address - exceptional return
point, means caller is not ready to process exceptions. To call
"unexpected()" is only way to continue or it is better to say "only
way to exit".
I hope you have surprised, as if you find
void somefunc(void) virtual() inline() throw();
declaration
. I want to say, that this is unexpected place of
linkage type keywords
One can see, that there are two types of exception declaration:
logical and hardware(linkage).
Declaration:
[hardware (linkage)]
[type]
[function name]
[(]
[list of parameters]
[)]
[logical]
[;]
hardware: virtual, inline, nothrow, extern "", stdcall, register, etc
logical: throw(type), const, etc
is best solution.
examples:
inline nothrow
void
somefunc(); //throw() is default here by nothrow
Here exit with unexpected() if somefunc throw, there is no hardware
overhead.
inline
void
somefunc(void)throw();
Here can add/replace throw std::unexpected_exception if somefunc
throw, there is hardware overhead, but process is reliable for
exceptions.
inline
void
somefunc(void)throw(my_type&);
Here can add/replace throw std::unexpected_exception if somefunc throw
unrelated to my_type, there is hardware overhead, but process is
reliable for exceptions.
One of the problem is necessity of C++ stacked exceptions instead of
single exception. In the case we must not replace original exception
with std::unexpected_exception instead of add the
std::unexpected_exception for original exception.
Maksim A. Polyanin
http://grizlyk1.narod.ru/cpp_new