Michael Hathcock wrote:
> "What are all the con's to using the C++ try-throw-catch syntax for
> handling program errors?"
The cons are numerous and awful, mostly having to do with the fact that
it's very difficult to /actually/ handle exceptions properly. A
discussion as to the finer points would probably be best at
comp.lang.c++, but see http://www.gotw.ca/gotw/059.htm
to start thinking
about the challenges ahead of you.
> In the early versions of C++, this system used by C++ was said to be
> horrible due to code-bloat and a performance hit (in terms of speed.)
As usual, people overstated the cost of the various mechanisms that C++
added to C, mostly because anyone trying to implement similar mechanisms
would do so with substantially more overhead.
> In C errors are handled by using return values and countless return
> value checks.
If that's how you coded in C, you should keep coding that way in C++.
Exceptions in C++ are largely an C++-aware revision to the
setjmp()/longjmp() style of programming that many C coders would use. If
you've never used setjmp() and longjmp() in your C code, well, it's
probably better to keep it that way. :)
> The engine that I am designing is currently using the try-throw-catch
> syntax and a custom exception class that I wrote. In the long run, will
> this syntax choke the game engine or will the extra sup****t code C++
> uses (the extra code to handle function calls, stack unwinding) to
> implement the syntax have minimal impact?
It depends how you use it, like everything else in programming. The act
of incrementing an integer variable is fairly quick, but if you do it a
trillion times, it'll cut into the time that you have available for
other tasks.
I would suggest you design your code in a text editor with the help of a
compiler. Then you can actually test some of these questions out
yourself easily and get proof with your own eyes. (Insert suggestion to
check out and start doing Test Driven Development as appropriate.)
FWIW, I have written fairly heavily exception-laden code in the past.
Rarely was it worth the trouble for anything more than trivial code,
because of all of the extra things you need to keep in mind and properly
handle. It's probably been five years since I've typed 'try' in a C++
program though, as proper software design tends to steer you away from
"complex" mechanisms like exception handling anyway.
g'luck,
-tom!
--


|