Free Software programmer
Subscribe This blog existed before my current employment, and obviously reflects my own opinions and not theirs. This work is licensed under a Creative Commons Attribution 2.1 Australia License.
Categories of this blog:
Older issues: |
Sun, 05 Jun 2005Exceptions revisited: the destructor relationshipSo David White (of Wesnoth fame) made an excellent point on my previous problem with exceptions. The problem of exceptions unexpectedly exiting out the side doesn't exist if every object cleans up in destructors (ie. use RAII . In other words, all state changes must be encapsulated in a class. This might seem obvious to people who deal with exceptions day-to-day (my C++ experience predates widespread use of exceptions). But encapsulating things in an object has one advantage: the programmer knows they cannot allocate memory in the destructor, The problem comes when not everything has a destructor, as will tend to happen when C code (and C programmers) using "exceptions" like my example. [/tech] permanent link |