What You’ll Learn in This Hour:
• How to respond to exceptions in your Java programs
• How to create methods that ignore an exception, leaving it for another class to handle
• How to use methods that cause exceptions
• How to create your own exceptions
Errors, the bugs, blunders, and typos that prevent a program from running correctly, are a natural part of the software development process. “Natural” is probably the kindest word that’s ever been used to describe them. In my own programming, when I can’t find the cause of an elusive error, I use words that would make a gangsta rapper blush.
Some errors are flagged by the compiler and prevent you from creating a class. Others are noted by the interpreter in response to a problem that keeps it from running successfully. Java divided errors into two categories:
• Exceptions—Events that signal an unusual circumstance has taken place as a program runs
• Errors—Events that signal the interpreter is having problems that might be unrelated to your program
Errors normally aren’t something a Java program can recover from, so they’re not the focus of this hour. You might have encountered an OutOfMemoryError
as you worked on Java programs; nothing can be done to handle that kind of error. The program exits with the error.
Exceptions often can be dealt with in a way that keeps a program running properly.
18.226.170.187