I heartily agree. I know there is a growing movement that likes to throw
execptions as "return codes" but I find it be annoying. It's find if you
potential for crashing the program on a normal function failure increases.
On Wed, 30 May 2007 21:11:46 GMT, MrAsm <mrasm@usa.com> wrote:
On Wed, 30 May 2007 15:39:00 -0500, "Doug Harrison [MVP]"
<dsh@mvps.org> wrote:
It depends. If I wanted to handle errors on the spot, I wouldn't want to
use exceptions, because that would amount to an expensive, obfuscating
form
of return code.
If the OP wants to also extract the number value, could it be a good
solution?
If he wanted to perform the conversion and handle the error on the spot, I
think he'd be better off using strtod, strtol, or strtoul, and I linked to
messages describing their use in my first reply.
He could also catch exception bad_lexical_cast, and so infer that the
input string does not store a valid number.
What I'm getting at is that it's a misuse of exceptions to litter your
code
with:
try
{
int x = lexical_cast<int>(s);
}
catch (bad_lexical_cast)
{
whatever;
}
It's much better to use one of the aforementioned functions and just test
return codes. The exception approach makes sense if you are not handling
the error locally but someplace upwards in the call chain.
--
Doug Harrison
Visual C++ MVP