a) what is the meaning of "throw new MyException()"?
throw is keyword in java used to throw either exceptions or errorsnew is used to create a new object MyException is our user defined exception as we are extending the Exception class
b) Do we require MyException class in hand before writing the class TestExt ?
There is no need to write the MyException class before the TestEx class
a) what is the meaning of "void doStuff() throws MyException" ? why throws MyException is attached with method?
throws is a keyword that says "the method or the init block can throw exception"void doStuff throws MyException means "dostuff method CAN throw MyException i.e. doStuff code can cause MyException"
writing above means we are declaring the exception
and writing the code in try catch block means handling the exception
hope this helps
SCJP 6 [86%], OCPWCD [84%], OCEJPAD [83%]
If you find any post useful, click the "plus one" sign on the right