Saturday, June 7, 2008

Errors, Bugs, and Exceptions

No programmer is perfect. Writing software is a complex undertaking, and given this complexity, it is quite common for even the best software to be shipped with various problems. Sometimes the problem is caused by "bad code" (such as overflowing the bounds of an array). Other times, a problem is caused by bogus user input that has not been accounted for in the application's code base (e.g., a phone number field assigned "Chucky"). Now, regardless of the cause of said problem, the end result is that your application does not work as expected. To help frame the upcoming discussion of structured exception handling, allow me to provide definitions for three commonly used anomaly-centric terms:

  • Bugs: This is, simply put, an error on the part of the programmer. For example, assume you are programming with unmanaged C++. If you make calls on a NULL pointer or fail to delete allocated memory (resulting in a memory leak), you have a bug.
  • User errors: Unlike bugs, user errors are typically caused by the individual running your application, rather than by those who created it. For example, an end user who enters a malformed string into a text box could very well generate an error if you fail to handle this faulty input in your code base.
  • Exceptions: Exceptions are typically regarded as runtime anomalies that are difficult, if not impossible, to account for while programming your application. Possible exceptions include attempting to connect to a database that no longer exists, opening a corrupted file, or contacting a machine that is currently offline. In each of these cases, the programmer (and end user) has little control over these "exceptional" circumstances.

No comments: