So I have an error message that gets thrown in one file
$error_message = "Error received for " . $service . ": " . $_r['status'] . "\n" . "Message received: " . $_r['errors'];
throw new My_Exception($error_message);
and in another file I have
try { //blah blah } catch( My_Exception $e ) { var_export($e->getMessage()); }
The problem, however, is that $_r['errors'] is an ARRAY and it get $e->getMessage() just prints it as "Array". How can I modify this code to access the array?
The problem is that You're trying to merge array with a string. It'll always end like this.
Maybe You should pass to exception an array, so You can later make use of it?
<?php
class myException extends Exception {
private $params;
public function setParams(array $params) {
$this->params = $params;
}
public function getParams() {
return $this->params;
}
}
// later it can be used like this:
try {
$exception = new myException('Error!');
$exception->setParams(array('status' => 1, 'errors' => array());
throw $exception;
}
catch (myException $e) {
// ...
}
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With