[PHP错误异常]①①--自定义异常类

MyException.php

出现异常了,信息如下";
        $message .= "

" . __CLASS__ . "[{$this->code}]:{$this->message}

"; return $message; } public function test() { echo "this is a test"; } public function stop() { exit('script end...'); } //自定义其他方法 } try { echo "出现异常啦"; throw new MyException('测试自定义异常', 3); } catch (MyException $e) { echo $e->getMessage();//测试自定义异常 echo "
"; echo $e;//tostring echo "
"; $e->test();//this is a test echo "
"; $e->stop();//script end... } echo "
"; echo "continue..."; ?>
[PHP错误异常]①①--自定义异常类_第1张图片
Paste_Image.png

你可能感兴趣的:([PHP错误异常]①①--自定义异常类)