I have a custom class:
class ActivationService extends SmsException {
public function __construct()
{
$this->sms = new SmsSender();
}
public function method(){
throw new SmsException(); // My custom exception
}
public function send(){
$this->sms->sendSms($this->phone); // Here's where the error appeared
}
}
So, when I call $this->sms->sendSms
I get an error from class sms
.
I'm catching the custom exception like as:
try {
$activationService = new ActivationService();
$activationService->send($request->phone);
}
catch (SmsException $e) {
echo 'Caught exception: ', $e->getMessage(), "
";
}
But when I get the error inside the library (class SmsSender
) in method: send()
I can not catch it and I get the error.
How can I fix it?