Page 1 of 1

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

Posted: Thu Nov 27, 2014 5:35 pm
by nmmedina
In this question, we're dealing with a user-created 'checked' exception (the parent is 'Exception', not 'RuntimeException').

One of the 2 correct answers (option 'E') is an overriding method without a throws clause. I thought 'checked' exceptions always had to be handled either with a try/catch block (which is not the focus of the question) or by throwing the checked exception. So not throwing anything doesn't seem a good answer. Isn't that so?

Thanks.

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

Posted: Fri Nov 28, 2014 2:01 am
by admin
You are not applying the concept correctly. It is true that if a code in a method throws a checked exception, it must either be caught or if the method wants to throw it out of itself, the method must declare it in its throws clause.

However, in this case, we are overriding the method itself. It is ok for an overriding method to specify that it will not throw any checked exception out to the caller. So even though the code in the overridden method may throw a checked exception (and that is why that method has specified it in its throws clause), that code will not even execute once it is overridden. The code written inside the overriding method will execute instead and it is ok for that code to not throw any exception.

I am guessing that you are confused about the concept of overriding. The overriding method does not call the overridden method in any hidden/implicit fashion if that is what you are thinking.

HTH,
Paul.

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

Posted: Sat Nov 29, 2014 12:13 am
by nmmedina
OMG, you're right. For some strange reason, only when dealing with exceptions in overriding methods, my brain would apply the concept of method overriding differently and incorrectly. I wasn't realizing what I was doing. Thanks for pointing it out.

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

Posted: Thu May 25, 2023 5:24 pm
by Kolodets
enthu.trans.FrameCollisionException is not a subclass of enthu.trans.ChannelException, at least it doesn't seem to be.
How comes the overriden connect method can throw enthu.trans.FrameCollisionException?
Or is that a subclass of ChannelException but I don't see?