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 31STQ
Program Plan Intro

Try and catch block:

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. It is possible to have a “try” block inside another large “try” block and “catch” block.
  • • “catch” block: Catch block catch exception thrown by the try block to handle it.

Syntax:

// class definition

class class_name

{

    // Try block

    try

    {

        // Try block statement

    }

  // Catch block

    catch(Excep1 exObj)

    {

        // Catch block statement

    }

}

Blurred answer
Students have asked these similar questions
Can you have a try block and corresponding catch blocks inside another,larger catch block?
Is it possible to include a try block and its associated catch blocks inside a larger catch block?
Is there a limit to how many parameters a catch block may have?

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