CHAPTER 11

Exceptions

During the execution of an application, there are many times when an error condition arises within the application. In Java, all kinds of error conditions are called exceptions. In this chapter, we look at how error conditions can occur during the execution of any of the methods, and how such error conditions may be handled by the invoker of the methods. Exceptions may occur due to various reasons at runtime. It could be due to wrong (unexpected) inputs from the user or non-availability of certain resources, which our code depends on. To understand error conditions, let us start by looking at a simple code segment as given below:

    1 int a = 75;
 2 int b = 0;
 3 int c = a / b;

What happens when the above code segment ...

Get The class of Java 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.