Custom Errors Series: Part 1 – What is an Exception

What is an Exception
An Exception is the object class that is created by .Net when an error or unexpected state is encountered while executing application code.  All Exceptions inherit from the System.Exception class.  The Exception object that is created when an error occurs contains error details including the stack trace and potentially any underlying exceptions that may have occurred.  The errors that occur fall into three basic categories only one of which is potentially exposed through Exception objects :

  • Syntax / Compile Errors
  • Runtime Errors
  • Logic Errors

These errors are listed in order of easiest to most difficult to find.

Syntax errors represent some coding error that the compiler can generally find for you they are the easiest to find.  In most Integrated Development Environments (IDE) the offending code will be underlined with a red squiggly.

Runtime errors are a little more difficult to find because as the name implies they do not occur until runtime; when a user actually runs the application.  The runtime error will only occur if the user presses the button or performs the action that runs the piece of code containing the error.  When the code is executed and the error occurs an Exception object will be created.  It is up to the developer to plan for this and “Handle” the Exception in a graceful way. However, if no one ever presses the button the error may never be found.

Logic Errors are the most difficult to find because even when the offending code is executed no error occurs and no exception object is created.  The error could be as simple as text behind a graphic instead of in front or a decimal point in the wrong place.  In any event it will require a human or an automated test check the expected output for known inputs to find the error.

For more on the different types of exceptions see the next post in this series

Custom Error Series –Part 2 – Types of Exceptions

Leave a Reply

Shopping Cart