Java: An Introduction to Problem Solving and Programming (8th Edition)
Java: An Introduction to Problem Solving and Programming (8th Edition)
8th Edition
ISBN: 9780134462035
Author: Walter Savitch
Publisher: PEARSON
bartleby

Concept explainers

Question
Book Icon
Chapter 9.3, Problem 25STQ
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.

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”

“throws” clause:

  • • This clause is used to declare the exception. This provides information to the programmer that the program might produce an exception so it is better to give the exception handling code which maintains the normal flow of the program.
  • • It is usually given in the method header.

Syntax:

Method_Name throws ExceptionName

{

    //statements

}

Blurred answer
Students have asked these similar questions
What happens when an exception occurs in a method but it is not caught inside the method?   The method exits immediately.   The exception is passed to the caller.   An exception is thrown.   All of the other answers are correct.
What happens if an exception is thrown, but not caught?
What will happen if an exception is thrown but not caught?

Chapter 9 Solutions

Java: An Introduction to Problem Solving and Programming (8th Edition)

Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
  • Text book image
    EBK JAVA PROGRAMMING
    Computer Science
    ISBN:9781337671385
    Author:FARRELL
    Publisher:CENGAGE LEARNING - CONSIGNMENT
    Text book image
    Microsoft Visual C#
    Computer Science
    ISBN:9781337102100
    Author:Joyce, Farrell.
    Publisher:Cengage Learning,
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,