Hour 18. Handling Errors in a Program

No subject in this tutorial is less popular than the one you're about to tackle: errors. Errors—the various bugs, blunders, typos, and other problems that stop a program from running successfully—are a natural part of the software development process. "Natural" is probably the kindest word that has ever been used to describe them—in my own Java programming, when I can't find the cause of an elusive error that keeps my program from working, 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. There are two kinds of problems you will encounter in Java:

  • Exceptions— Events that signal an unusual circumstance has taken place as a program runs
  • Errors— Events that signal the interpreter is having problems that may be unrelated to your program

During this hour, we'll explore exceptions as the following topics are discussed:

  • How to use methods that cause exceptions
  • 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 create your own exceptions

You'll also learn how to keep errors out of your programs using a language feature called assertions.

      
Comments