so your sample code will not be good, but assuming
$_r['errors'] = array( 'Message 1', 'Message 2', 'Message 3', 'Message 4', 'Message 5', );
Then
$error_message = "Error received for " . $service . ": \n" . impolode("\n", $_r['errors']) . "\n" . "Message received: " . $_r['errors']; throw new My_Exception($error_message);
The key takes your array of error messages and combines them with newlines (or something else)
But I agree with the comment that you may incorrectly use the Exception structure. Can you post what you are trying to do?
The general rule is that you throw an exception for each unique event. You do not collect a bunch of error messages, and then throw them all at once.
Francis yaconiello
source share