Skip to Content
Learning Java, 6th Edition
book

Learning Java, 6th Edition

by Marc Loy, Patrick Niemeyer, Daniel Leuck
August 2023
Beginner
552 pages
15h 14m
English
O'Reilly Media, Inc.
Book available
Content preview from Learning Java, 6th Edition

Chapter 6. Error Handling

You will always encounter errors in the real world. How you handle them helps show the quality of your code.

Java has its roots in embedded systems—software that runs inside specialized devices, such as the handheld computers, cellular phones, and fancy toasters that we might consider part of the internet of things (IoT) these days. In those applications, it’s especially important that software errors be handled robustly. Most users would agree that it’s unacceptable for their phone to crash on a regular basis or for their toast (and perhaps their house) to burn because some software failed. Given that we can’t eliminate the possibility of software errors, recognizing and dealing with application-level errors methodically is a good step in the right direction.

Some languages leave the responsibility for handling errors entirely with the programmer. The language itself provides no help in identifying error types and no tools for dealing with them easily. In the C language, for example, functions generally indicate a failure by returning an “unreasonable” value (like the idiomatic -1 or a null). As the programmer, you must know what constitutes a bad result and what it means. It’s often awkward to work around the limitations of passing error values in the normal path of data flow.1 An even worse problem is that certain types of errors can legitimately occur almost anywhere, and it’s slow and costly to test for them explicitly at every point in the software. ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Head First Java, 3rd Edition

Head First Java, 3rd Edition

Kathy Sierra, Bert Bates, Trisha Gee
Learning Java, 4th Edition

Learning Java, 4th Edition

Patrick Niemeyer, Daniel Leuck
Java in a Nutshell, 7th Edition

Java in a Nutshell, 7th Edition

Benjamin J. Evans, David Flanagan

Publisher Resources

ISBN: 9781098145521Errata PageSupplemental Content