Java: An Introduction to Problem Solving and Programming (7th Edition)
Java: An Introduction to Problem Solving and Programming (7th Edition)
7th Edition
ISBN: 9780133766264
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
What outcomes are possible in the event that an exception is thrown outside of a try block?
Explain the difference between a try block and a catch block.
What sort of code is included in a try-catch statement's try block?

Chapter 9 Solutions

Java: An Introduction to Problem Solving and Programming (7th 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.
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
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,