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
Question
Book Icon
Chapter 9.3, Problem 26STQ
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 is exception propagation? Give an example of a class that contains at least two methods, in which one method calls another. Ensure that the subordinate method will call a predefined Java method that can throw a checked exception. The subordinate method should not catch the exception. Explain how exception propagation will occur in your example.
Write a class TimeOfDay that uses the exception classes defined in the previous exercise. Give it a method setTimeTo(timeString) that changes the time if timeString corresponds to a valid time of day. If not, it should throw an exception of the appropriate type. [Java]
Java Foundations :  Please provide code and explain. Thank you. Write the code segments in main( ) and in methodA( ) for the following scenario:   main( ) passes methodA an int variable called a.    methodA generates an exception, but does not deal with it, if a is not between 1 and 100.

Chapter 9 Solutions

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

Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
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