【发布时间】:2016-12-12 21:57:53
【问题描述】:
我正在尝试将数组作为异常传递。稍后我会将其编码为 json。
try {
class myException extends Exception {
private $params;
public function setParams(array $params) { $this->params = $params; }
public function getParams() { return $this->params; }
}
throw new myException(
array(
'error' => array(
'status' => true,
'code' => '12',
'note' => 'Does NOT contain application/json'
)
)
);
} catch (myException $e) {
print_r($e->getParams());
}
但不断收到以下错误:
致命错误:未捕获错误:myException([string $message [, long $code [, Throwable $previous = NULL]]]) in /home/domain/script.php:79 堆栈跟踪:
#0 /home/domain/script.php(79): Exception->__construct(Array)
#1 {main} 在第 79 行的 /home/domain/script.php 中抛出
甚至可以传递数组吗?
如果是这样,我的代码有什么问题?
【问题讨论】: