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

  • SEARCH
  • Home
  • 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 9097109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:01:33+00:00 2026-06-17T00:01:33+00:00

have a following problem: I have an abstract class with a method call that

  • 0

have a following problem:

I have an abstract class with a method “call” that basically calls some otherMethod and if otherMethod throws an Exception I try to fix in catch by relogging and calling the “call” method again.

public Object call(String methodName, Object[] parameters, Class[] parameterTypes) throws RetryingException, RemoteException {
    while (true) {
        try {
            return callMethod(methodName, parameters, parameterTypes);
        } catch (SomeException e) {
            if (numberOfTriesLeft-- == 0) {
                throw new RetryingException();
            }
            login();
        }
    }
}

Now I have a subclass of this class with overriden method call that may take a null parameter. Basically if such situation happens I want to call the method from superclass, but the Exception mentioned above is not thrown, thus, no retry and method ends failing somewhere else. Is there a way to throw it manually and pass further or any other way to fix it? Thank you for your help!

@Override
public Object call(String methodName, Object[] parameters, Class[] parameterTypes) throws RetryingException, RemoteException {
    if (parameters[0] == null){
        // What to do here if I want to throw SomeException here to end up in a catch block from the call method in the superclass? Or how to change it
    }
    // Everything ok. No null params
    ...
    return super.call(methodName, parameters, parameterTypes);
}
  • 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-17T00:01:34+00:00Added an answer on June 17, 2026 at 12:01 am

    From my experience, what you could do is to have a parent method like so:

    public final Object call(String methodName, Object[] parameters, Class[] parameterTypes) throws RetryingException, RemoteException {
        try {
            callMethod(methodName, parameters, parameterTypes)
        } catch (Exception ex) {
            // Handle any exception here...
        }
    }
    
    protected Object callMethod(String methodName, Object[] parameters, Class[] parameterTypes) throws RetryingException, RemoteException {
        // .. your code
    }
    

    And then override the callMethod (child) method instead:

    @Override
    protected Object callMethod(String methodName, Object[] parameters, Class[] parameterTypes) throws RetryingException, RemoteException {
        // Exception thrown here will now be caught!
        return super.callMethod(methodName, parameters, parameterTypes);
    }
    

    So this has separated the interface methods from the overrideable methods. I see this pattern quite a lot in existing APIs.

    Some points:

    • call is now final stopping it from being overridden.
    • callMethod is protected making it only override-able and callable from the same package – taking it out of the public API.

    Update: Taken on board the point provided by @Fildor.

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

Sidebar

Related Questions

Okay so basically I have the following problem: I'm trying to have an abstract
I have a base class that has an abstract getType() method. I want subclasses
Consider the following problem: You have a class 'A' that serves as a base
I have the following abstract base class in which i have an abstract method.
Hi i have following Problem. I write a Mediawiki Extension where i need some
Within my code a have the following abstract superclass public abstract class AbstractClass<Type extends
I have the following setup: abstract class AParentLy{ private $a; private $b; function foo(){
I have following method in my class which extends JTable: protected void setTableCursor(Cursor cursor)
I have a class Packet with an abstract method getID : Type Packet =
I'm using a third party library class that has the following (abbreviated) method: public

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.