Category: 

What is Exception Handling?

Article Details
  • Written By: Jessica Susan Reuter
  • Edited By: A. Joseph
  • Image By: ビッグアップジャパン
  • Last Modified Date: 17 September 2016
  • Copyright Protected:
    2003-2016
    Conjecture Corporation
  • Print this Article
Free Widgets for your Site/Blog
Built at the request of Dag Hammarskjöld, the United Nations Headquarters has a meditation room dedicated to silence.   more...

October 1 ,  1890 :  Yosemite National Park was established.  more...

Exception handling is a common programming language construct that allows programs to identify and gracefully handle mistakes that they might encounter as they run. It works by changing the flow of a program from normal execution to a specific set of mitigating actions when a mistake is found. A programmer can create specific sets of actions that are invoked when certain mistakes happen. Finding and handling exceptions is not necessarily a fatal event for a program; it is sometimes possible for program execution to continue after exception handling occurs.

It is often possible, while programming a specific piece of code, for one to determine exactly where exception handling is necessary. In that case, most programming languages, including Java and C++, have specific keywords and control structures that can be placed into code to handle errors. These structures can handle a wide variety of errors, and with proper maintenance, it is often possible for a programmer to foresee the majority of possible errors for a particular piece of code.

Exception handling can also be useful for parsing input. For example, when parsing numeric input, one can immediately tell if a piece of data is non-numeric if the proper test and exception handler is set up. If an exception occurs, the handler catches it, which immediately tells the program that input is invalid. What happens next depends on how the rest of the program is structured; it might exit, or it might continue and simply ignore the invalid input.

Ad

Proper exception handling does not guarantee flawless program execution. It also doesn't guarantee that a program will stop after an error is found, and it doesn't guarantee that a program will continue. In order to handle errors properly, a programmer must use exception handling in conjunction with common sense and careful attention to detail. Ideally, proper error handling will allow a program to avoid the most serious types of errors, such as invalid memory accessing, while giving informative messages about fixable issues, such as invalid input or unexpected problems with a program's execution.

Exception handling catches errors called "run time" errors; it does not guarantee that code is free from bugs or syntax errors. Having error handling in code does not guarantee that the code is correct. It is possible for error handling to miss bugs in code, and even the best error catching is rarely foolproof. After debugging is complete, the presence of exception handling allows for much easier code maintenance and future debugging, if necessary.

Ad

You might also Like

Recommended

Discuss this Article

Post your comments

Post Anonymously

Login

username
password
forgot password?

Register

username
password
confirm
email