11.2 Example: Divide by Zero without Exception Handling
First we demonstrate what happens when errors arise in an application that does not use exception handling. Figure 11.1 prompts the user for two integers and passes them to method quotient
, which calculates the integer quotient and returns an int
result. In this example, you’ll see that exceptions are thrown (i.e., the exception occurs) when a method detects a problem and is unable to handle it.
The first sample execution in Fig. 11.1 shows a successful division. In the second execution, the user enters the value 0 as the denominator. ...
Get Java How to Program (early objects), 9/e 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.