Page 1 of 1

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

Posted: Wed Apr 15, 2015 8:41 am
by rafaparche
Question ask about what kind of objects can be thrown using a throw statement? Throwable and Exception are obvious but RuntimeException is thrown by jvm not by user, isn't?


Thanks!

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

Posted: Wed Apr 15, 2015 10:21 am
by admin
Not necessarily. You can throw any exception including RuntimeException using a throw statement.

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

Posted: Wed Aug 21, 2019 12:34 pm
by leonardofaria00
A resposta correta seria: Throwable, Exception e RuntimeException?

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

Posted: Wed Aug 21, 2019 7:50 pm
by admin
Can you write it in English please?

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

Posted: Sun Nov 17, 2019 9:49 am
by girishankaran
The correct answer would be: Throwable, Exception and RuntimeException

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

Posted: Sat Dec 05, 2020 8:02 am
by noeloo
Exception and Error are two main subclasses of Throwable.
What are the other subclasses?

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

Posted: Sat Dec 05, 2020 8:49 am
by admin
There are several but not direct. Updated the explanation to make it clearer.

thank you for your feedback!

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

Posted: Thu Mar 09, 2023 3:41 pm
by labutis
You can only throw a Throwable using a throws clause
Is this true? It seems that I can throw new Throwable(), just like with any other exception.

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

Posted: Thu Mar 09, 2023 10:56 pm
by admin
labutis wrote:
Thu Mar 09, 2023 3:41 pm
You can only throw a Throwable using a throws clause
Is this true? It seems that I can throw new Throwable(), just like with any other exception.
Yes, it is correct. You quoted only half of the sentence. The complete sentence written in the explanation is:
You can only throw a java.lang.Throwable object (i.e. an instance of Throwable or any of its direct or indirect subclasses) using a throws clause.
Please check the part written within the parentheses. That should make it clear.

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

Posted: Sun Mar 12, 2023 2:48 pm
by labutis
Thanks!
From the explanation, I got the impression, that
you can only throw a Throwable object using a THROWS clause,
but I should've read It
is you can only throw a THROWABLE object using a throws clause
:)