How to catch an exception from another class?
<p>I have a custom class:</p>

<pre><code>class ActivationService extends SmsException {

    public function __construct()
    {
          $this-&gt;sms = new SmsSender();
    }

    public function method(){
        throw new SmsException(); // My custom exception
    }


    public function send(){
        $this-&gt;sms-&gt;sendSms($this-&gt;phone); // Here's where the error appeared
    }
}
</code></pre>

<p>So, when I call <code>$this-&gt;sms-&gt;sendSms</code> I get an error from  class <code>sms</code>.</p>

<p>I'm catching the custom exception like as:</p>

<pre><code>try {    
    $activationService = new ActivationService();
    $activationService-&gt;send($request-&gt;phone);    
}
catch (SmsException $e) {    
    echo 'Caught exception: ', $e-&gt;getMessage(), "\n";
}
</code></pre>

<p>But when I get the error inside the library (<code>class SmsSender</code>) in method: <code>send()</code> I can not catch it and I get the error.</p>

<p>How can I fix it?</p>