Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The assignment will test your understanding of handling and working with Java Throwables. The file below contains a class that includes several empty functions. Through

The assignment will test your understanding of handling and working with Java Throwables. The file below contains a class that includes several empty functions. Through the process of implementing these functions, you will develop the skills of working with Java Throwables. Please refer to the below file for the documentation on what needs to be implemented for each of the functions.

package homework; import java.io.IOException; import java.util.function.Supplier; public class Homework { /** * This function should throw an throw an Exception * @throws Exception */ public static void throwException() throws Exception { } /** * This function should throw a ClassCastException with the specified message string. * @param message */ public static void throwExceptionWithMessage(String message){ } /** * This function should throw the exception it is given. * @param e * @throws Exception */ public static void throwThisException(Exception e) throws Exception { } /** * This function should invoke the runnable. If the runnable throws an exception this function should catch the * exception and return the message of the exception. If the runnable does not throw and exception if should return * the message string it is given as its first parameter. * * To invoke the runnable call "runnable.run()". * * @param message * @param runnable * @return */ public static String catchAndReturnMessage(String message, Runnable runnable){ return null; } /** * Invoke the runnable function if there is any type of throwable thrown by this function this function should * throw an IOException with the cause being the original throwable thrown by the specified runnable function. * If the runnable does not throw a throwable this function should return. To invoke the runnable call * "runnable.run()". * @param runnable * @throws IOException */ public static void catchAndThrowNew(Runnable runnable) throws IOException{ } /** * This function is given several suppliers and a single runnable. This function should return the string supplied by * the supplier named main. To invoke the main supplier call "main.get()" The main supplier has a chance of throwing * several different types of runtime exceptions. If the main supplier throws an SecurityException or a IllegalStateException return the value * supplied by the handleDouble function "return handleDouble.get()". If the main supplier throws a * NoSuchElementException return the value supplied by the handleNoSuchElement function "return * handleNoSuchElement.get()". For all other Runtime exceptions return the value supplied by the handleOthers function. * The function cleanup should always be invoked after the aforementioned functions regardless of if there is an error or * not. * @param main * @param handleDouble * @param handleNoSuchElement * @param handleOthers * @param cleanup * @return */ public static String catchCleanupAndRun(Supplier main, Supplier handleDouble, Supplier handleNoSuchElement, Supplier handleOthers, Runnable cleanup){ return null; } /** * This function will be given a Supplier known as supplier and a runnable known as cleanup. The supplier is a * lambda function that will return a string. To invoke the supplier you call "supplier.get()" which will return * a string this function should return the string returned by the supplier. After the supplier is invoked the * cleanup function should be invoked. This function should always be invoked after the supplier is invoked regardless * if there is an exception or an error thrown by the supplier. The clean up function must only be invoked after * the supplier is invoked. To invoke the cleanup function you call "cleanup.run()". The supplier has a possibility * of throwing and exception. If the supplier throws an exception this function should throw a new Runtime exception * with the message from the exception thrown by the supplier as the message of the new Runtime exception. * @param supplier A function to be invoked the return value should be returned by this function * @param cleanup A function that should be invoke after the supplier is invoked regardless if an exception is * thrown by the supplier or not. * @return The return value of the suppler. */ public static String catchCleanupAndThrow(Supplier supplier, Runnable cleanup){ return null; } } 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Repairing And Querying Databases Under Aggregate Constraints

Authors: Sergio Flesca ,Filippo Furfaro ,Francesco Parisi

2011th Edition

146141640X, 978-1461416401

More Books

Students also viewed these Databases questions

Question

=+ Who do you think is right? Why?

Answered: 1 week ago