CHAPTER 19

EXCEPTION HANDLING

An unusual situation may occur sometimes while running the programs. There might be errors and some of them may be fatal. Take a simple case of divide by zero. Older languages give some error message and halt the execution of the program. If the errors are fatal, one cannot do anything about it but if they are non-fatal, the language should allow us to do some damage control exercise. Java provides elegant way of exception handling precisely for this purpose.

19.1 Why Use Exception Handling

One of the most important reasons for handling exception is that when a program terminates abruptly many undesirable things happen. Certain resources, like open files and the World Wide Web (WWW) connection, remain blocked. The ...

Get Programming with 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.