MyException.php
<?php
class MyException extends Exception
{
public function __construct($message, $code = 0)
{
parent::__construct($message, $code);
}
public function __toString()
{
$message = "<h2>出現(xiàn)異常了窄俏,信息如下</h2>";
$message .= "<p>" . __CLASS__ . "[{$this->code}]:{$this->message}</p>";
return $message;
}
public function test()
{
echo "this is a test";
}
public function stop()
{
exit('script end...');
}
//自定義其他方法
}
try {
echo "出現(xiàn)異常啦";
throw new MyException('測試自定義異常', 3);
} catch (MyException $e) {
echo $e->getMessage();//測試自定義異常
echo "<hr/>";
echo $e;//tostring
echo "<hr/>";
$e->test();//this is a test
echo "<hr/>";
$e->stop();//script end...
}
echo "<hr/>";
echo "continue...";
?>
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者