About Question enthuware.ocajp.i.v7.2.1223 :
Moderator: admin
-
- Posts: 1
- Joined: Sun Apr 06, 2014 11:23 am
- Contact:
About Question enthuware.ocajp.i.v7.2.1223 :
It must declare throws ArrayIndexOutOfBoundsException, StringIndexOutOfBoundsException...
If I understand the explanation declaring RuntimeExceptions is optional and not a must.
So why is "It must ..." correct?
If I understand the explanation declaring RuntimeExceptions is optional and not a must.
So why is "It must ..." correct?
-
- Site Admin
- Posts: 10067
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1223 :
This option is not marked as correct.
If you like our products and services, please help us by posting your review here.
-
- Posts: 35
- Joined: Mon Jul 28, 2014 2:05 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1223 :
"It must declare throws ArrayIndexOutOfBoundsException, StringIndexOutOfBoundsException" still marked as correct one.
-
- Posts: 35
- Joined: Mon Jul 28, 2014 2:05 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1223 :
sorry, that's not true. Just looked at checkbox, not at correct answerspfilaretov wrote:"It must declare throws ArrayIndexOutOfBoundsException, StringIndexOutOfBoundsException" still marked as correct one.
-
- Posts: 2
- Joined: Thu Oct 16, 2014 7:35 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1223 :
Can you please elaborate on your explanation and answers.
-
- Site Admin
- Posts: 10067
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1223 :
Sure, if you can tell which part do you have a problem understanding, I can explain further.
If you like our products and services, please help us by posting your review here.
-
- Posts: 5
- Joined: Tue Apr 14, 2015 9:32 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1223 :
Hi, I don't understand why It is ok if it declares just throws ArrayIndexOutOfBoundsException and It does not need to declare any throws clause are valid answers?
Thanks!
Thanks!
-
- Site Admin
- Posts: 10067
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1223 :
Since ArrayIndexOutOfBoundsException is a RuntimeException, it can be specified in any throws clause without any issue. Also, since it is a RuntimeException, there is no need to specify it in any throws clause either.
I suggest you to write some code to try out a few scenarios involving this.
HTH,
Paul
I suggest you to write some code to try out a few scenarios involving this.
HTH,
Paul
If you like our products and services, please help us by posting your review here.
-
- Posts: 7
- Joined: Thu Mar 30, 2017 7:15 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1223 :
Consider the following hierarchy of Exception classes :
java.lang.RuntimeException
+-------- IndexOutOfBoundsException
+---------ArrayIndexOutOfBoundsException, StringIndexOutOfBoundsException
Which of the following statements are correct for a method that can throw ArrayIndexOutOfBounds as well as StringIndexOutOfBounds Exceptions but does not have try catch blocks to catch the same?
"The method calling this method will either have to catch these 2 exceptions or declare them in its throws clause"
This option is not valid in this question is because it is case of Runtime exception, but it would have been correct if it was case of Compile time exception right?
java.lang.RuntimeException
+-------- IndexOutOfBoundsException
+---------ArrayIndexOutOfBoundsException, StringIndexOutOfBoundsException
Which of the following statements are correct for a method that can throw ArrayIndexOutOfBounds as well as StringIndexOutOfBounds Exceptions but does not have try catch blocks to catch the same?
"The method calling this method will either have to catch these 2 exceptions or declare them in its throws clause"
This option is not valid in this question is because it is case of Runtime exception, but it would have been correct if it was case of Compile time exception right?
-
- Site Admin
- Posts: 10067
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1223 :
Yes, it would have been correct if they were checked exceptions. The method could also either catch a super class of these two exceptions (such as Exception or Throwable) or declare in its throws clause.
If you like our products and services, please help us by posting your review here.
-
- Posts: 10
- Joined: Wed Aug 08, 2012 5:00 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1223 :
Hi All,
Why the following is wrong?
It must declare throws ArrayIndexOutOfBoundsException, StringIndexOutOfBoundsException
and how this is right?
It is ok if it declares just throws ArrayIndexOutOfBoundsException
Thanks
Why the following is wrong?
It must declare throws ArrayIndexOutOfBoundsException, StringIndexOutOfBoundsException
and how this is right?
It is ok if it declares just throws ArrayIndexOutOfBoundsException
Thanks
-
- Site Admin
- Posts: 10067
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1223 :
Already explained above. It is invalid because of "must".
Since both are RuntimeExceptions, there is no need to specify them in any throws clause.
Since both are RuntimeExceptions, there is no need to specify them in any throws clause.
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: Bing [Bot] and 216 guests