“Jeffrey began his talk by defining an exception as an event that occurs when an implicit assumption is violated, and not as many people erroneously believe, simply a rarely occurring event. When an implicit assumption is violated, an exception event should be generated rather than having the function return an error code. Jeffrey gave a great example of how the legacy tradition of returning a -1 for a file read function at the end of a file is actually improper and how it can cause coding difficulties and application errors.
Richter presented an impressive list of the benefits of exception handling. By using more robust, maintainable object oriented code, the result is cleaner, uncluttered centralized program logic. One of the unexpected benefits of exception handling is better performance because many errors can be processed centrally instead of after each function call. Although some early implementations of exception handling using C++ had poor performance, the efficiency of Microsoft’s .NET garbage collector has all but eliminated these problems.
Jeffrey ended his talk with guidelines and best practices for exception handling including liberal use of finally blocks, catching specific exceptions (only lazy developers catch all), graceful recovery design pattern, and backing out but not swallowing of exceptions.
In his presentation on exception handling, Jeffrey did more than describe the rules and show code examples for exception handling on .NET (which, of course, he did exceptionally well). He described a common sense way of looking at exceptions that everyone in the audience could understand. Jeffrey said that an exception occurs when an implicit assumption is violated, and not, as many people erroneously believe, when a rare event has occurred. Richter ended his talk on a positive note, demonstrating that proper handling of exceptions produces cleaner, less cluttered code that is easy to understand and is highly performant.” [ebig newsletter]