0

Hi,

I have two classes.
I user throw new Exception("Error"); in first class.
I want to catch that error message in second class with "try catch".

How do i do it?

Thanks

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by veledrom
0

You haven't shown any code so the best I can do is give a short example:

class someClassA
{
  public function someMethodA()
  {
    throw new Exception("Error");
  }
}

class someClassB
{
  public function someMethodB()
  {
    $someInstA = new someClassA();
    try
    {
      $someInstA->someMethodA();
    }
    catch (Exception $e)
    {
      echo $e->getMessage();
    }
  }
}
0

Sorry for not adding my code but your code helped me update my code and solved the problem.
Thanks very much

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.