我可以在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();
}