Big Java Late Objects
Big Java Late Objects
2nd Edition
ISBN: 9781119330455
Author: Horstmann
Publisher: WILEY
Question
Book Icon
Chapter 7.4, Problem 20SC
Program Plan Intro

Exception:

  • It is nothing but an undesirable or unexpected event that occurs at run time which interrupts the normal flow of the program’s commands.
  • Exception handling is a mechanism that handle runtime errors like “ClassNotFoundException”, “SQLException”, and so on.
  • An advantage of exception handling is to maintain a flow of the program.
  • An exception can be handled using “try” and “catch” block.

Catching exception:

Java virtual machine (JVM) searches to handle the error in “catch” clause at that time of exception in the program. So “try-catch” statements are used in order to handle those exceptions. The following are the main keywords used in exception handling.

  • “try” block: Try block contains the block of statements to monitor the exception and it thrown the exception.
  • “catch” block: Catch block catch exception thrown by the try block to handle it.

Types of exceptions:

There are two types of exceptions. They are:

  • Checked Exception:
    • A class that inherits a “Throwable” class except “RunTimeException” and “Error” are called as checked exceptions.
    • Example: “IOException”
  • Unchecked Exception:
    • A class that inherits a “RunTimeException” class is called as unchecked exceptions.
    • Example: “ArrayIndexOutOfBoundException”

Blurred answer
Knowledge Booster
Background pattern image
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education