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

Recommended Answers

All 2 Replies

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();
    }
  }
}

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.