Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8712601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:08:38+00:00 2026-06-13T05:08:38+00:00

Suppose we have this problem public class Father{ public void method1(){…} } public class

  • 0

Suppose we have this problem

public class Father{
    public void method1(){...}
}

public class Child1 extends Father{
    public void method1() throws Exception{
    super.method1();
    ... 
    }

}

Child1 extends Father and overrides method1 but given the implementation Child1.method1 now throws a exception. This won’t compile as the overriding method can’t throw new exceptions.

What is the best solution?

  • Propagate the required exception to the Father. To me this is against encapsulation, inheritance and general OOP (the Father potentially throws an exception that will never happen).
  • Use a RuntimeException instead? This solution won’t propagate the Exception to the Father, but Oracle docs and other sources state that class of exceptions should be used when “Client code cannot do anything”. This is not that case, this exception will be useful to recover blablabla (why is it wrong to use RuntimeException instead?).
  • Other..
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T05:08:39+00:00Added an answer on June 13, 2026 at 5:08 am

    Using RTE is not a bad idea. This is the methodology of Spring framework and it works quite fine. If you are implementing application probably use this solution.

    If however you are implementing library that exposes API IMHO you should use checked exception. In this case you should create your own exception for example BaseException. Method method() of Father will throw it. The define ChildException extends BaseException and declare method1() of child class to throw it.

    This does not break encapsulation: base class throws base exception. It does not have any idea about the concrete exception. Child class throws concrete exception that however extends base exception and therefore can be treated by client code as base exception.

    As an example I can give you IOException and FileNotFoundException that extends it. You can work with input stream catching IOException while the concrete stream is FileInputStream and it throws FileNotFoundException. But client does not know this. It catches IOException.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have this class hierarchy: class A { public: virtual void foo(Base *b)
Suppose I have this: public class Unit<MobileSuit, Pilot> { ... List<MobileSuit> mobileSuits; List<Pilot> pilots;
public class XPBN extends Activity{ private Map _map; @Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState);
Suppose I have a simple Java class like this: public class User { String
Suppose I have a domain model like this: public class MyDomainEntity { public double
Suppose I have this: class Validator { private $db; public checkIfUsernameAlreadyExists($username) { if (!$this->db)
Suppose I have a Java class like this: public class Test { static {
My problem is quite simple Suppose I have those class: public class A {
So, I have a little problem here. Suppose I have: public class Repository<TEntity> where
I tried many ways to solve this problem but none works. suppose I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.