Re: Percentage of error checking code
On Tuesday, February 26, 2013 6:51:34 PM UTC, Paavo Helde wrote:
=D6=F6 Tiib <ootiib@hot.ee> wrote in
news:0a0bdcbd-06ce-4ada-9deb-93ff5347c247@googlegroups.com:
For example in the light of OP question they try to fix
programming errors runtime. It is impossible task since
programming errors are in the part that "fixes" too.
For programming errors there are various asserts.
Incidentally, it appears our codebase contains slightly more
assert lines than throw lines.
And what about error checking that uses neither asserts nor
exceptions?
Or more generally: what about a program that uses the classical
line oriented input idiom:
std::string line;
int lineNumber = 0;
while ( std::getline( file, line ) ) {
++ lineNumber;
std::istringstream parser( line );
if ( parser >> i >> j >> k ) { // For example...
// ...
}
}
What part of that code is "error handling"? Without any error
checking, it might be simply:
while ( file >> i >> j >> k ) {
}
No need to keep track of the line number, for example, if I'm
not going to output it in case of an error. No need for the
separate `std::istringstream` if I don't need to check the
format, and resynchronize in case of an error. And so on.