Q: Please explain the following sentence: 'Use exceptions where you really need them -- not only do they have high basic cost, but their presence can hurt compiler analysis.'
A: Only when the situation is truly exceptional should you use this mechanism, though you may be tempted to throw exceptions simply to take advantage of their control-flow aspects. A good use of this mechanism would be to throw an exception if a file could not be found; a poor use would be to throw an exception with the name of a file that had been found. In the former case, the cost of the mechanism would only be incurred when the app was unable to proceed normally; in the latter case the cost would be incurred all the time without any added benefit.
Learn more about this topic
- The Java Programming Language by Ken Arnold and James Gosling (Addison Wesley, 1997) devotes a section of its chapter on exceptions to this issue