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
please solve this important, thanks.
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.
java

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
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning