Chapter 18. Handling Errors in a Program

<feature><title></title>

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

</feature>

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 ...

Get Sams Teach Yourself Java™ in 24 Hours, Fifth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.