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

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

Moderator: admin

Post Reply
ashishrai.kv
Posts: 33
Joined: Tue Jan 09, 2018 2:12 am
Contact:

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

Post by ashishrai.kv »

Assume that a method named 'method1' contains code which may raise a non-runtime (checked) Exception.
What is/are the possible way(s) to declare this method so that it indicates that it expects the caller to handle that exception?

please explain the above question, i am confused about when to use throws and when to use throw?

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

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

Post by admin »

"throws" is used to declare that a method may throw a particular exception. For example, void m1() throws IOException; This means that the method m1 may throw IOException to the caller of this method at run time. i.e. if the caller calls this method, it may receive IOException.

"throw" is used to actually throw an exception. For example the code for method m1 may have something like this -
if(f == null) throw new FileNotFoundException();

If this statement is executed at runtime, the caller of m1 will get FileNotFoundException.

You should go through this topic from a good book before attempting mock questions because this is quite fundamental.

ashishrai.kv
Posts: 33
Joined: Tue Jan 09, 2018 2:12 am
Contact:

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

Post by ashishrai.kv »

thank you.
already read the ocajp7 but still a little confused

Post Reply

Who is online

Users browsing this forum: vs2013 and 7 guests