【发布时间】:2013-03-06 23:11:36
【问题描述】:
我可以在extend Exception 类中添加什么以及如何使用它?如您所见,我在catch 块中包含了错误处理。
例如:
class Manager {
private $socket = null;
private $config = array();
public function connect($host = null, $port = null) {
if ($host == null || $port == null) {
throw new PortHostNotGivenException('Host or Port is missing');
}
$this->socket = fsockopen($host,$post);
}
}
class PortHostNotGivenException extends Exception {
// What to put here??
}
测试:
$ast = new Manager();
try {
$ast->connect();
} catch (PortHostNotGivenException $e) {
// Log Error to File
// Log Error to Linux Console
echo $e . '/r/n';
exit();
}
【问题讨论】:
标签: php error-handling try-catch