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 8374569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:57:05+00:00 2026-06-09T14:57:05+00:00

I have this scenario: Interface ClassInterface { public function getContext(); } Class A implements

  • 0

I have this scenario:

Interface ClassInterface 
{
  public function getContext();
}

Class A implements ClassInterface 
{
  public function getContext()
  {
     return 'CONTEXTA';
  }

  //Called in controller class
  public function Amethod1() 
  {
    try {
       //assuming that Helper is a property of this class
        $this->helper->helperMethod($this);
     } catch(Exception $ex) {
       throw $ex;
     }
  }
}

Class B implements ClassInterface 
{
  public function getContext()
  {
     return 'CONTEXTB';
  }

  //Called in controller class
  public function Bmethod1() 
  {
     try {
       //assuming that Helper is a property of this class
        $this->helper->helperMethod($this);
     } catch(Exception $ex) {
       throw $ex;
     }
  }

}

Class Helper {
 public function helperMethod(ClassInterface $interface) 
 {
   try {
      $this->verifyContext($interface->getContext());
      //dosomething
   } catch(\Exception $ex) {
     throw $ex;
   }

 }

 private function verifyContext($context) {
    if (condition1) {
       throw new \UnexpectedValueException('Invalid context.');
    }

    return true;
 }

}

I want my controller class which calls Amethod1 and Bmethod1 to know the type of exception(s) thrown in the process. Is it advisable to rethrow an exception just like it was presented?
Do you think the throw-catch-throw-catch-throw structure reasonable in this case?

  • 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-09T14:57:07+00:00Added an answer on June 9, 2026 at 2:57 pm

    Yes, totally reasonable. But: your specific example can be simplified from:

    public function Amethod1() 
    {
       try {
          //assuming that Helper is a property of this class
          $this->helper->helperMethod($this);
       } catch(Exception $ex) {
          throw $ex;
       }
    }
    

    To:

    public function Amethod1() 
    {
    
        //assuming that Helper is a property of this class
        $this->helper->helperMethod($this);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this scenario well, i'll let the model explain. public class ScheduleMonthlyPerDayModel {
Please Consider this scenario: We have a base class called clsMain : class clsMain
I there, I have this scenario: public class A{ //attributes and methods } public
I'm a little bit confused by this scenario: I have a class that implements
Suppose I have this: @Transactional(rollbackFor = NotificationException.class) public interface PersonManagerService { public void addPerson(Person
In this scenario, I have 2 or more models: class Store(models.Model): name = models.CharField(max_length
I have a model that looks like this: public interface IEntity { int Id
Basically I have this scenario going on: //in interface header @property(nonatomic,retain)OtherClass *otherClass; //implementation -
I have this scenario. I want group on Country and Category. A store can
I have this scenario where I would like to redirect my domains using the

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.