Catching Twilio API exceptions- PHP

I am using Twilio to send SMS to users. On an invalid number, I am getting 400. How can I catch that exception or HTTP Status code so that I can handle it accordingly? It does return these codes and I want to know the HTTP Code received in the API response.
$client = new Client($account_sid, $auth_token);
$client->messages->create(
$to, array(
'body' => $message,
'from' =>$SMS_FROM
)
);
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: foreach() argument must be of type array|object, null given
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.