The catch block argument is ref variable of MyException. In the try block you are throwing the MyException (you just created a new instance of MyException and threw it), it is caught by the catch block. What is caught by the catch block is again thrown by it.
Be careful, if your doStuff wont declare MyException, it was Compiler error to write "throw me" inside the catch block, and it would be called unhandled exception.
The exception thrown in the try block is caught by the catch block and the exception rethrown in the catch block is simply ducked to the method doStuff(). And whichever methods call doStuff(), they will have to place this method call statement either in the try catch of declare the exception.
Joined: Apr 26, 2007
Hi chandra, I got it. I am not understanding the below mentioned code its from k&b.
Sub class can do the following: 1- Does not declare any exception 2- Declares the same exception 3- Declares subclass exception that is subclass of the parent class declared type exception 4- Declares/or throws any unchecked exception, as option "e" did, NumberFormatException is unchecked exception. 5- Does combination of 4 and 5 (checked as well as unchecked exceptions) as option "f" did. [ April 30, 2007: Message edited by: Chandra Bhatt ]