What is an Unhandled Exception?

What is an Unhandled Exception?
Coming up next: Action Statements: Definition & Examples

You're on a roll. Keep up the good work!

Take Quiz Watch Next Lesson
 Replay
Your next lesson will play in 10 seconds
  • 0:02 Definition of…
  • 0:49 Examples of Unhandled…
  • 1:44 Programming & Exceptions
  • 2:57 Lesson Summary
Add to Add to Add to

Want to watch this again later?

Log in or sign up to add this lesson to a Custom Course.

Log in or Sign up

Timeline
Autoplay
Autoplay
Speed
Lesson Transcript
Instructor: Martin Gibbs

Martin has 16 years experience in Human Resources Information Systems and has a PhD in Information Technology Management. He is an adjunct professor of computer science and computer programming.

We interrupt this program to bring you an unhandled exception. Unhandled exceptions are not pleasant as they can cause a program to crash. This lesson covers these exceptions and provides methods for avoiding them.

Definition of Unhandled Exception

Imagine you are watching your favorite television show and it is interrupted by an unscheduled infomercial. In programming, an exception is an unscheduled event in a computer program, much like the unwanted and extended advertisement. Exceptions are often synonymous with an error because something went wrong. An element in the code broke and now the program doesn't work.

Programming languages offer tools for catching exceptions and then displaying an error or starting over. Not everything can be anticipated, but it's good practice to prepare for errors as well as possible. If you don't have anything to catch a certain exception, it is called an unhandled exception.

Before we get too much further, let's take a look at how exceptions work in programming languages.

Examples of Unhandled Exceptions

Remember that an exception is an unscheduled interruption of normal program processing. When an error occurs, the compiler checks to see if there are any instructions available to handle that error. Let's say a letter gets put into a numeric field. The compiler asks if there is any way to handle that error. If there is, that code is run. Usually this means that some sort of warning is displayed, and the program continues on its way.

If no such method exists, then the compiler gives up and displays an unhandled exception error. It's as if the compiler is telling you 'I try to think, but nothing happens.'

The following scenarios could cause an unhandled exception:

  • Dividing by zero
  • Trying to read/write a file that isn't there
  • Trying to access an array element that doesn't exist
  • Using the wrong data type
  • Failure to convert string-to-number and vice versa
  • Security violation

Programming and Exceptions

Remember, if it can go wrong, it probably will. The codes that handle exceptions are called exception handlers. In languages like Java, you can try to execute some code then catch any exceptions that may arise. These are the actual Java keywords you use in this case. Languages like Java allow you to catch multiple exception types: numeric, string, file errors, read or write errors, etc.

To unlock this lesson you must be a Study.com Member.
Create your account

Register to view this lesson

Are you a student or a teacher?

Unlock Your Education

See for yourself why 30 million people use Study.com

Become a Study.com member and start learning now.
Become a Member  Back
What teachers are saying about Study.com
Try it risk-free for 30 days

Earning College Credit

Did you know… We have over 200 college courses that prepare you to earn credit by exam that is accepted by over 1,500 colleges and universities. You can test out of the first two years of college and save thousands off your degree. Anyone can earn credit-by-exam regardless of age or education level.

To learn more, visit our Earning Credit Page

Transferring credit to the school of your choice

Not sure what college you want to attend yet? Study.com has thousands of articles about every imaginable degree, area of study and career path that can help you find the school that's right for you.

Create an account to start this course today
Try it risk-free for 30 days!
Create An Account
Support