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();
}