5 Common exceptions
This chapter covers
- Ways to avoid
NullPointerException
in Java programs - Which mistakes cause
IndexOutOfBoundsExceptions
- Different reasons for
ClassCastException
- Finite and infinite recursion in Java
In this chapter, we discuss some of the most common exceptions in Java programs caused by bugs. This chapter differs somewhat from the others, as we will concentrate on the effects of the bugs, rather than their causes.
All the exception classes in Java inherit a single Throwable
class. Any exception can be thrown explicitly via a throw
statement. Some exceptions can be thrown by the virtual machine itself. Here, we will mainly speak about such exceptions. Figure 5.1 shows the hierarchy of exceptions covered in this chapter. ...
Get 100 Java Mistakes and How to Avoid Them 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.