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.
About Question enthuware.ocajp.i.v7.2.1049 :
Moderator: admin
-
- Posts: 3
- Joined: Sat Nov 01, 2014 4:46 pm
- Contact:
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1049 :
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.
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.
If you like our products and services, please help us by posting your review here.
-
- Posts: 3
- Joined: Sat Nov 01, 2014 4:46 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1049 :
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.
-
- Posts: 2
- Joined: Mon May 22, 2023 5:46 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1049 :
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?
How comes the overriden connect method can throw enthu.trans.FrameCollisionException?
Or is that a subclass of ChannelException but I don't see?
Who is online
Users browsing this forum: Google [Bot] and 114 guests