Introduction to Java Programming and Data Structures, Comprehensive Version Plus MyProgrammingLab with Pearson EText -- Access Card Package
bartleby

Concept explainers

Question
Book Icon
Chapter 12.7, Problem 12.7.1CP

a.

Program Plan Intro

Finally block:

Finally block contains block of code and the block is executed after a try-catch block.

  • If there is no errors in try block, finally statement is executed after try block executed.
  • If there is error in try block, then catch block caught the exception, rest of try block is skipped, and then executes the finally statement.
  • If there is error in try block, then catch block does not caught that exception, rest of try block is skipped, executes only finally statement, and then skip the rest of the code.
  • Thus, finally block handle such case and it contains block of statement. Once try-catch block gets executed, finally block is executed.

Rethrowing the exception:

  • An exception can be rethrown by a catch statement because; it can catch and handled by another catch statement.
  • It allows many handlers to access the exception.
  • However, the rethrown exception should not recaught by the same exception and should propagate to next catch statement.

In following class, first catch statement catches exception and rethrows it to another catch statement:

class Rethrow_exp

{

try

{

//... Try block statement

}

Catch statement rethrows the exception.

catch(Excep_type excep_obj)

{

//... Catch block statement

// Rethrow the exception

throw excep_obj

}

//...

}

Catch statement catches the rethrown the exception.

class rethrow_main

{

//...

catch(Excep_typeexcep_obj)

{

// Recatch block statement catches rethrown //exception

}

}

Therefore, an inner catch rethrow an exception to an outer catch.

Given code:

//Try block

try

{

statement1;

statement2;

statement3;

}

//Catch block

catch (Exception1 ex1)

{

}

//Catch block

catch (Exception2 ex2)

{

}

//Finally block

finally

{

statement4;

}

statement5;

b.

Program Plan Intro

Finally block:

Finally block contains block of code and the block is executed after a try-catch block.

  • If there is no errors in try block, finally statement is executed after try block executed.
  • If there is error in try block, then catch block caught the exception, rest of try block is skipped, and then executes the finally statement.
  • If there is error in try block, then catch block does not caught that exception, rest of try block is skipped, executes only finally statement, and then skip the rest of the code.
  • Thus, finally block handle such case and it contains block of statement. Once try-catch block gets executed, finally block is executed.

Rethrowing the exception:

  • An exception can be rethrown by a catch statement because; it can catch and handled by another catch statement.
  • It allows many handlers to access the exception.
  • However, the rethrown exception should not recaught by the same exception and should propagate to next catch statement.

In following class, first catch statement catches exception and rethrows it to another catch statement:

class Rethrow_exp

{

try

{

//... Try block statement

}

Catch statement rethrows the exception.

catch(Excep_type excep_obj)

{

//... Catch block statement

// Rethrow the exception

throw excep_obj

}

//...

}

Catch statement catches the rethrown the exception.

class rethrow_main

{

//...

catch(Excep_typeexcep_obj)

{

// Recatch block statement catches rethrown //exception

}

}

Therefore, an inner catch rethrow an exception to an outer catch.

Given code:

//Try block

try

{

statement1;

statement2;

statement3;

}

//Catch block

catch (Exception1 ex1)

{

}

//Catch block

catch (Exception2 ex2)

{

}

//Finally block

finally

{

statement4;

}

statement5;

c.

Program Plan Intro

Finally block:

Finally block contains block of code and the block is executed after a try-catch block.

  • If there is no errors in try block, finally statement is executed after try block executed.
  • If there is error in try block, then catch block caught the exception, rest of try block is skipped, and then executes the finally statement.
  • If there is error in try block, then catch block does not caught that exception, rest of try block is skipped, executes only finally statement, and then skip the rest of the code.
  • Thus, finally block handle such case and it contains block of statement. Once try-catch block gets executed, finally block is executed.

Rethrowing the exception:

  • An exception can be rethrown by a catch statement because; it can catch and handled by another catch statement.
  • It allows many handlers to access the exception.
  • However, the rethrown exception should not recaught by the same exception and should propagate to next catch statement.

In following class, first catch statement catches exception and rethrows it to another catch statement:

class Rethrow_exp

{

try

{

//... Try block statement

}

Catch statement rethrows the exception.

catch(Excep_type excep_obj)

{

//... Catch block statement

// Rethrow the exception

throw excep_obj

}

//...

}

Catch statement catches the rethrown the exception.

class rethrow_main

{

//...

catch(Excep_typeexcep_obj)

{

// Recatch block statement catches rethrown //exception

}

}

Therefore, an inner catch rethrow an exception to an outer catch.

Given code:

//Try block

try

{

statement1;

statement2;

statement3;

}

//Catch block

catch (Exception1 ex1)

{

}

//Catch block

catch (Exception2 ex2)

{

throw ex2;

}

//Finally block

finally

{

statement4;

}

statement5;

d.

Program Plan Intro

Finally block:

Finally block contains block of code and the block is executed after a try-catch block.

  • If there is no errors in try block, finally statement is executed after try block executed.
  • If there is error in try block, then catch block caught the exception, rest of try block is skipped, and then executes the finally statement.
  • If there is error in try block, then catch block does not caught that exception, rest of try block is skipped, executes only finally statement, and then skip the rest of the code.
  • Thus, finally block handle such case and it contains block of statement. Once try-catch block gets executed, finally block is executed.

Rethrowing the exception:

  • An exception can be rethrown by a catch statement because; it can catch and handled by another catch statement.
  • It allows many handlers to access the exception.
  • However, the rethrown exception should not recaught by the same exception and should propagate to next catch statement.

In following class, first catch statement catches exception and rethrows it to another catch statement:

class Rethrow_exp

{

try

{

//... Try block statement

}

Catch statement rethrows the exception.

catch(Excep_type excep_obj)

{

//... Catch block statement

// Rethrow the exception

throw excep_obj

}

//...

}

Catch statement catches the rethrown the exception.

class rethrow_main

{

//...

catch(Excep_typeexcep_obj)

{

// Recatch block statement catches rethrown //exception

}

}

Therefore, an inner catch rethrow an exception to an outer catch.

Given code:

//Try block

try

{

statement1;

statement2;

statement3;

}

//Catch block

catch (Exception1 ex1)

{

}

//Catch block

catch (Exception2 ex2)

{

throw ex2;

}

//Finally block

finally

{

statement4;

}

statement5;

Blurred answer
Students have asked these similar questions
The assignment here is to write an app using a database named CIT321 with a collection named students; we will provide a CSV file of the data. You need to use Vue.js to display 2 pages. You should know that this assignment is similar, all too similar in fact, to the cars4sale2 example in the lecture notes for Vue.js 2. You should study that program first. If you figure out cars4sale2, then program 6 will be extremely straightforward. It is not my intent do drop a ton of new material here in the last few days of class. The database contains 51 documents. The first rows of the CSV file look like this: sid last_name 1 Astaire first_name Humphrey CIT major hrs_attempted gpa_points 10 34 2 Bacall Katharine EET 40 128 3 Bergman Bette EET 42 97 4 Bogart Cary CIT 11 33 5 Brando James WEB 59 183 6 Cagney Marlon CIT 13 40 GPA is calculated as gpa_points divided by hrs_attempted. GPA points would have been arrived at by adding 4 points for each credit hour of A, 3 points for each credit hour of…
I need help to solve the following case, thank you
hi I would like to get help to resolve the following case

Chapter 12 Solutions

Introduction to Java Programming and Data Structures, Comprehensive Version Plus MyProgrammingLab with Pearson EText -- Access Card Package

Ch. 12.4 - Prob. 12.4.3CPCh. 12.4 - Prob. 12.4.4CPCh. 12.4 - Prob. 12.4.5CPCh. 12.4 - Prob. 12.4.6CPCh. 12.4 - What is displayed when running the following...Ch. 12.4 - Prob. 12.4.8CPCh. 12.4 - What does the method getMessage() do?Ch. 12.4 - What does the method printStackTrace() do?Ch. 12.4 - Prob. 12.4.11CPCh. 12.4 - Prob. 12.4.12CPCh. 12.5 - Prob. 12.5.1CPCh. 12.6 - Prob. 12.6.1CPCh. 12.7 - Prob. 12.7.1CPCh. 12.8 - Prob. 12.8.1CPCh. 12.9 - Prob. 12.9.1CPCh. 12.9 - Prob. 12.9.2CPCh. 12.10 - What is wrong about creating a File object using...Ch. 12.10 - How do you check whether a file already exists?...Ch. 12.10 - Can you use the File class for I/O? Does creating...Ch. 12.11 - Prob. 12.11.1CPCh. 12.11 - Prob. 12.11.2CPCh. 12.11 - Prob. 12.11.3CPCh. 12.11 - Prob. 12.11.4CPCh. 12.11 - What will happen if you attempt to create a...Ch. 12.11 - Prob. 12.11.6CPCh. 12.11 - Suppose you enter 45 57, 8 789, then press the...Ch. 12.11 - Prob. 12.11.8CPCh. 12.12 - How do you create a Scanner object for reading...Ch. 12.13 - Prob. 12.13.1CPCh. 12.13 - Simplify the code in lines 20-28 as follows: 1....Ch. 12 - Prob. 12.1PECh. 12 - (InputMismatchException) Write a program that...Ch. 12 - (ArrayIndexOutOfBoundsException) Write a program...Ch. 12 - (IllegalArgumentException) Modify the Loan class...Ch. 12 - (IllegalTriangleException) Programming Exercise...Ch. 12 - (NumberFormatException) Listing 6.8 implements the...Ch. 12 - Prob. 12.7PECh. 12 - Prob. 12.8PECh. 12 - Prob. 12.9PECh. 12 - Prob. 12.10PECh. 12 - Prob. 12.11PECh. 12 - (Reformat Java source code) Write a program that...Ch. 12 - (Count characters, words, and lines in a file)...Ch. 12 - (Process scores in a text file) Suppose a text...Ch. 12 - (Write/read data) Write a program to create a file...Ch. 12 - Prob. 12.16PECh. 12 - (Game: hangman) Rewrite Programming Exercise 7.35....Ch. 12 - Prob. 12.18PECh. 12 - (Count words) Write a program that counts the...Ch. 12 - Prob. 12.20PECh. 12 - (Data sorted?) Write a program that reads the...Ch. 12 - Prob. 12.22PECh. 12 - (Process scores in a text file on the Web) Suppose...Ch. 12 - (Create large dataset) Create a data file with...Ch. 12 - (Create a directory) Write a program that prompts...Ch. 12 - Prob. 12.26PECh. 12 - (Replace words) Suppose you have a lot of files in...Ch. 12 - (Rename files) Suppose you have a lot of files in...Ch. 12 - (Rename files) Suppose you have several files in a...Ch. 12 - (Occurrences of each letter) Write a program that...Ch. 12 - (Baby name popularity ranking) The popularity...Ch. 12 - (Ranking summary) Write a program that uses the...
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
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
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning