Re: Exception handling Organization: unknown
On Sep 23, 4:21 pm, George Neuner <gneun...@comcast.net> wrote:
Yeah, but a radio connection can go up and down every few seconds in
an electrical storm. By ordinary conventions, "connection broken"
would be an exceptional condition. For a remote device operating
under such conditions, a potentially flaky radio connection is normal
operation - not exception.
Here's one more angle: when connection is lost, what are repercussions
on the code? Does it go out of a 10-level deep call stack? If so,
exception is miles better readability-wise.
Frankly, this is my favorite criteria. Readability first!
Compare...
Error-return:
result fX()
{
// Code, code, code
result r=(fXPlus1());
if (iserror(r))
return r; // RAII handles cleanup.
// now imagine above three lines repeated many times in the code,
// in various places, in f1-f10. I __know__ what happens in case of
an
// error, don't make me read it repeatedly, friggin' please!
// Code, code, code
}
and
void buckStopsHere()
{
while (whatewer)
{
result r = f1();
if (iserror(r)) report error;
}
}
Exception:
void fX()
{
// Code, code, code
fXPlus1();
// Code, code, code
}
and
void buckStopsHere()
{
while (whatewer)
{
try { f1(); }
catch(const connectionBroken& error)
{ report error; }
}
}
Goran.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]