NewToCPP wrote:
I have seen at several places that C++ programmers writing for RealTime
Embedded applications dont use Exception Handling. They dont like
Throw/catch concept. WHY?
My shop doesn't use exceptions for the following possibly
invalid reasons:
0) Earlier compilers did a poor job of generating code.
1) Earlier developers over-used exceptions. The used
exceptions to return status rather than just exceptional conditions.
2) Earlier developers were not aware of how to write
exception-safe code. They didn't follow the law-of-threes and
didn't make the assignment operator exception-safe.
3) Most of the developers write C in C++ (at least we got them
to stop writing FORTRAN in C++).
3) Unexpected exception handling in C++ is incompatible with
most embedded systems (actually IMHO it is incompatible with
most applications).
If you know how to write exception-safe code, you get big
rewards. You can't use the RAII paradigm without using
exceptions for the simple reason exceptions are the only way to
report an error from a constructor. Use constructors to
encapsulate any change of state if you need to clean up that
change of state later. Unless you use RAII you're likely to
have memory leaks, unreleased locks, and other resource leaks.
Make the compiler do the work for you.
Glen Dayton