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

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
akash701
Posts: 2
Joined: Sat Apr 12, 2014 8:59 am
Contact:

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

Post 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;

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

You might want to go through this first before attempting questions on exceptions - http://www.geeksforgeeks.org/checked-vs ... s-in-java/

eddie3
Posts: 14
Joined: Sat Dec 17, 2016 10:17 pm
Contact:

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

Post 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?

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

What happened when you tried it out?

eddie3
Posts: 14
Joined: Sat Dec 17, 2016 10:17 pm
Contact:

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

Post by eddie3 »

The compiler won't actually tell me if it's myException3 that gets thrown or myException that gets thrown.

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.

crazymind
Posts: 85
Joined: Mon Dec 24, 2018 6:24 pm
Contact:

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

Post by crazymind »

If MyException3() comes before the MyException() (switch the order of catch block), what gonna happen?

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

What happened when you tried it out?

Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests