Robert FisherJust thinking out loud On exceptionsIf you register and log in you can add comments to my pages. If viewing the main blog page, click the # underneath an entry to comment on it. Recently, I've had to write some C++ code & couldn't use exceptions. This reëmphasized to me what a boon they are. Consider this contrived example:
That code spends so much time checking & rechecking for error conditions. Now consider the same thing with exceptions.
An error is only checked where it happens & is only reported/handled where it can be. The intervening code remains simple. Now imagine a real program...
Exceptions can be a big win in cleaner, simpler, quicker to write, easier to maintain code—even if the implementation does have a performance hit. Although this does gloss over the dtors or finally blocks that are needed to ensure proper clean-up when an exception happens. (But you need that without exceptions as well.) last updated 1 year ago # |