Tasks:1.usetheextendskeywordtocreateacustomexceptionclassMyException.2.createasecondexceptionclassMySpecialExceptionwhichisasubclassofMyException.3.createaclassExceptionT...
Tasks:
1.use the extends keyword to create a custom exception class MyException.
2.create a second exception class MySpecialException which is a subclass of MyException.
3.create a class ExceptionTest.
a. The class has two methods testMException() and testMSException(). The method testMException prints a message “MyException is thrown” and throws MyException. The method testMSException prints a message “MySpecialException is thrown” and throws MySpecialException..
b. In the main() method of the class, the two methods testMException() and testMSException() are invoked. testMException() and testMSException() are put
into two different try-catch blocks. For each method, first MySpecialException is caught and then MyException is caught and then a finally clause is used at the end of all the exception handlers. In the catch clause to catch MySpecialException, a message “MySpecialException is caught” is printed. In the catch clause to catch MyException, a message “MyException is caught” is printed. In the finally clause, a message “Here is finally clause” is printed.
c. After finally clause, print a message “This is the end of main() method”.
4.run the program, observe the result and make clear why such a result is produced.
5.modify the program, move the two methods testMException() and testMSException() into one try-catch block and remove the redundant try-catch block. Please compare the result with the former result and understand why such a result is produced.
展开