
Concept explainers
a.
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.
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.
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.
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;

Want to see the full answer?
Check out a sample textbook solution
Chapter 12 Solutions
MyLab Programming with Pearson eText -- Access Card -- for Introduction to Java Programming and Data Structures, Comprehensive Version
- Using R language. Here is the information link. http://www.cnachtsheim-text.csom.umn.edu/Kutner/Chapter%20%206%20Data%20Sets/CH06PR18.txtarrow_forwardUsing R languagearrow_forwardHow can I type the Java OOP code by using JOptionPane with this following code below: public static void sellCruiseTicket(Cruise[] allCruises) { //Type the code here }arrow_forward
- Draw a system/level-0 diagram for this scenario: You are developing a new customer relationship management system for the BEC store, which rents out movies to customers. Customers will provide comments on new products, and request rental extensions and new products, each of which will be stored into the system and used by the manager for purchasing movies, extra copies, etc. Each month, one employee of BEC will select their favorite movie pick of that week, which will be stored in the system. The actual inventory information will be stored in the Entertainment Tracker system, and would be retrieved by this new system as and when necessary. Example of what a level-0 diagram looks like is attached.arrow_forwardWhat is the value of performing exploratory data analysis in designing data visualizations? What are some examples?arrow_forwardDraw a level-0 diagram for this scenario: You are developing a new customer relationship management system for the BEC store, which rents out movies to customers. Customers will provide comments on new products, and request rental extensions and new products, each of which will be stored into the system and used by the manager for purchasing movies, extra copies, etc. Each month, one employee of BEC will select their favorite movie pick of that week, which will be stored in the system. The actual inventory information will be stored in the Entertainment Tracker system, and would be retrieved by this new system as and when necessary.arrow_forward
- Draw a context diagram for this scenario: You are developing a new customer relationship Management system for the BEC store, which rents out movies to customers. Customers will provide comments on new products, and request rental extensions and new products, each of which will be stored into the system and used by the manager for purchasing movies, extra copies, etc. Each month, one employee of BEC will select their favorite movie pick of that week, which will be stored in. the system. The actual inventory information will be stored in the Entertainment Tracker system, and would be retrieved by this new system as and when necessary.arrow_forwardWrite a complete Java program named FindSumAndAverage that performs the following tasks in 2-D array: Main Method: a. The main() method asks the user to provide the dimension n for a square matrix. A square matrix has an equal number of rows and columns. b. The main() method receives the value of n and calls the matrixSetUp() method that creates a square matrix of size n and populates it randomly with integers between 1 and 9. c. The main method then calls another method named printMatrix() to display the matrix in a matrix format. d. The main method also calls a method named findSumAndAverage() which: • Receives the generated matrix as input. • Calculates the sum of all elements in the matrix. • Calculates the average value of the elements in the matrix. • Stores these values (sum and average) in a single-dimensional array and returns this array • e. The main method prints the sum and average based on the result returned from findSumAndAverage()). Enter the dimension n for the square…arrow_forwardThe partial sums remain the same no matter what indexing we done to s artial sum of each series onverges, * + s of each series to the series or show 12. (1)+(0)+(0)+(+1)+ 17, " (F) + (F) + (F)(F)(- 18. 19. 1 #20. (三)+(三)-(三)+(3) 20 (9)-(0)-(0)-- 10 +1 2.1+(男)+(男)+(罰)+(鄂 9 T29 x222-끝+1-23 + -.... Repeating Decimals 64 Express each of the numbers in Exercises 23-30 as the m integers. 23. 0.23 = 0.23 23 23... 24. 0.234 = 0.234 234 234. 25. 0.7 = 0.7777... 26. 0.d = 0.dddd... where d is a digit natio of own s converges or * 27. 0.06 = 0.06666.. 28. 1.4141.414 414 414... 29. 1.24123 = 1.24 123 123 123... 30. 3.142857 = 3.142857 142857. Using the ath-Term Test In Exercises 31-38, use the ath-Term Test for divergence to show that the series is divergent, or state that the test is inconclusive 8arrow_forward
- CPS 2231 Computer Programming Homework #3 Due Date: Posted on Canvas 1. Provide answers to the following Check Point Questions from our textbook (5 points): a. How do you define a class? How do you define a class in Eclipse? b. How do you declare an object's reference variable (Hint: object's reference variable is the name of that object)? c. How do you create an object? d. What are the differences between constructors and regular methods? e. Explain why we need classes and objects in Java programming. 2. Write the Account class. The UML diagram of the class is represented below (10 points): Account id: int = 0 - balance: double = 0 - annualInterestRate: double = 0.02 - dateCreated: java.util.Date + Account() + Account(id: int, balance: double) + getId(): int + setId(newId: int): void + getBalance(): double + setBalance(newBalance: double): void + getAnnualInterestRate(): double + setAnnualInterest Rate (newRate: double): void + toString(): String + getDataCreated(): java.util.Date +…arrow_forwardTHIS IS NOT A GRADING ASSIGNMENT: Please only do lab 2.2 (bottom part of the first picture) For that Lab 2.2 do: *Part 1 (do the CODE, that's super important I need it) *Part 2 *Part 3 I also attached Section 2.5.2 which is part of the step 1 so you can read what is it about. Thank you!arrow_forwardTHIS IS NOT A GRADING ASSIGNMENT: Please only do lab 2.2 (bottom part of the first picture) For that Lab 2.2 do: *Part 1 *Part 2 *Part 3 I also attached Section 2.5.2 which is part of the step 1 so you can read what is it about. Thank you!arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrProgramming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage Learning




