Page 1 of 1

About Question enthuware.ocajp.i.v7.2.1323 :

Posted: Sat Apr 12, 2014 9:26 am
by akash701
class MyException extends Throwable{}
Is this MyException checked exception or what?
void myMethod() throws MyException{
throw new MyException3();
This method is throwing new MyException3 but the throws statement mention MyException?
Is it valid to mention some Exception with throws statement and then actually throwing some other Exception in the body? I mean can they differ?

Thanks a lot;

Re: About Question enthuware.ocajp.i.v7.2.1323 :

Posted: Sat Apr 12, 2014 10:03 am
by admin
akash701 wrote:class MyException extends Throwable{}

Is this MyException checked exception or what?
What do you think? :)
void myMethod() throws MyException{
throw new MyException3();

This method is throwing new MyException3 but the throws statement mention MyException?
Is it valid to mention some Exception with throws statement and then actually throwing some other Exception in the body? I mean can they differ?

Thanks a lot;
Myexception3 is also there in the code.

Re: About Question enthuware.ocajp.i.v7.2.1323 :

Posted: Sun Apr 13, 2014 12:09 am
by admin
You might want to go through this first before attempting questions on exceptions - http://www.geeksforgeeks.org/checked-vs ... s-in-java/

Re: About Question enthuware.ocajp.i.v7.2.1323 :

Posted: Sat Dec 17, 2016 10:22 pm
by eddie3
After this this code:

Code: Select all

void myMethod( ) throws MyException{
         throw new myException3( );
         }
Which exception actually gets thrown ? Is it myException3 or myException? If myException is thrown, will a catch(myException3 e) block effectively catch it?

Re: About Question enthuware.ocajp.i.v7.2.1323 :

Posted: Sat Dec 17, 2016 11:12 pm
by admin
What happened when you tried it out?

Re: About Question enthuware.ocajp.i.v7.2.1323 :

Posted: Sun Dec 18, 2016 1:42 pm
by eddie3
The compiler won't actually tell me if it's myException3 that gets thrown or myException that gets thrown.

Re: About Question enthuware.ocajp.i.v7.2.1323 :

Posted: Sun Dec 18, 2016 10:14 pm
by admin
Of course not. Exception is thrown at run time. So you need to put your code in a class and call it from main. Then execute the class and you will see the result on the command line.

Re: About Question enthuware.ocajp.i.v7.2.1323 :

Posted: Wed Dec 26, 2018 11:07 am
by crazymind
If MyException3() comes before the MyException() (switch the order of catch block), what gonna happen?

Re: About Question enthuware.ocajp.i.v7.2.1323 :

Posted: Wed Dec 26, 2018 11:10 am
by admin
What happened when you tried it out?