Commit df0779fb by Qiang Xue

Added previous exception in toArray().

parent 172f40aa
...@@ -29,11 +29,24 @@ class Exception extends \Exception implements Arrayable ...@@ -29,11 +29,24 @@ class Exception extends \Exception implements Arrayable
*/ */
public function toArray() public function toArray()
{ {
return array( $array = array(
'type' => get_class($this), 'type' => get_class($this),
'name' => $this->getName(), 'name' => $this->getName(),
'message' => $this->getMessage(), 'message' => $this->getMessage(),
'code' => $this->getCode(), 'code' => $this->getCode(),
); );
if (($prev = $this->getPrevious()) !== null) {
if ($prev instanceof self) {
$array['previous'] = $prev->toArray();
} else {
$array['previous'] = array(
'type' => get_class($prev),
'name' => 'Exception',
'message' => $prev->getMessage(),
'code' => $prev->getCode(),
);
}
}
return $array;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment