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 solutionChapter 12 Solutions
Introduction to Java Programming and Data Structures: Brief Version (11th Global Edition)
- What is the shortest path from vertex 3 to all other vertices:Which graph algorithm can solve the problem most efficiently(the quickest runtime)How could the same algorithm if the graph had edge weights? (create intermediate nodes)arrow_forwardThe difference between (1) a database management system (DBMS) and (2) a database, is: a. The first refers to a complete accounting system, the second refers to a subset of that b. The first is program software, the second is proprietary data and related files c. The first is hardware, the second is software d. Nothing—these terms are synonyms..arrow_forwarda) An example of the linear hash index is given below. Every time a new overflow page is added, the bucket pointed by Next is split, and Next is incremented by one. Show the index state after adding the keys 39, 25, and 29. hi ho Level=0, N=4 000 00 0*8* 001 01 17*33* 010 10 6*26* 42* 011 11 7* 11* 15* 23* 100 00 4* 12* 20* 101 01 5* 13* 21* 37* Nextarrow_forward
- What would be the runtime (big-O asymptotic notation) of Dijkstra’s algorithm if it is implemented based on an unsorted minimum priority queue in terms of vertices (v) and edges (e)? Please show all steps including the runtime of each step of the algorithm.arrow_forwarda) An extendable hashing index is given below. Present the state of the index after adding the keys 21, 25, and 29. Directory Buckets 0*8* 12* 20* 00 9* 13*33* 01 10 6*26* 42* 11 7* 11* 15*23* b) Explain the concepts of global depth and local depth of buckets. Which buckets in the index above (after inserting 21, 25 and 29) have a global depth equal to the local depth? c) Describe the bulk loading algorithm for B+ trees. What are the differences to using a simple B+ tree add operation?arrow_forwardb) Below is an example of a B+ tree. Add an element with key 19 and then delete an element with key 1. Present the final result. 1* 3* . 10 18 24 27 37 10*15* - 18 20 22 24*26* 24* 26* - 27* 30*32* 37*40*arrow_forward
- Books (bid, author, title, publisher, year, notes); Members (mid, name, surname, street, city, country, phone, notes); Borrow (rid, bid, mid, date, notes);arrow_forwardCustomer (cid, name, surname, city, address, phone) Account (aid, cid, amount, currency, created) Deposit (did, aid, cid, amount, date) Withdraw(wid, aid, cid, amount, date)arrow_forwardData environment The SPJ company manages the orders of the parts from the suppliers for the projects that run at other companies. A project is described with the project identifier, name, company where the project takes part, budget, start date, and the duration of the project. A part is presented with the part identifier, name, and price. A supplier is described by the supplier identifier, name, address, city and phone number. For each order of a product from a given supplier for a given project, we store the number of parts ordered, the price of the order, the date, and the comment. The information system SPJ includes the following tables. Parts pid, name, price ); Projects( jid, name, company, budget, start, duration ); Suppliers sid, name, address, city, phone ); Orders oid, pid, jid, sid, quantity, price, date, comment );arrow_forward
- Data environment The SPJ company manages the parts orders from the suppliers for the projects that run at other companies. A project is described with the project identifier, name, company where the project takes part, budget, start date, and the duration of the project. A part is presented with the part identifier, name, and price. A supplier is described by the supplier identifier, name, address, city and phone number. For each order of a product from a given supplier for a given project, we store the number of parts ordered, the price of the order, the date, and the comment. The information system SPJ includes the following tables. Parts pid, name, price ); Projects( jid, name, company, budget, start, duration ); Suppliers sid, name, address, city, phone ); Orders oid, pid, jid, sid, quantity, price, date, comment );arrow_forwardAn example of a linear hash index is given below. Every time a new overflow page is added, the bucket pointed by Next is split and Next is incremented by one. Show the index state after adding the keys 10, 13, and 15. h₁ ho Level=0, N=4 000 00 0*8* 001 01 9* 25* 33* Next 010 10 6* 26* 42* 46* 011 11 7* 11*23* 100 00 4* 12*20* 101 01 5* 29* 37*21*arrow_forwardCustomer (cid, name, surname, city, address, phone); Account (aid, cid, amount, created, comment); Transfer (tid, from_aid, to_aid, cid, amount, date, descr);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