php7中系统自带异常类和自己创建异常类比较

php7中系统自带异常类和自己创建异常类

1,系统自带异常类 try catch
<?php
try{
throw new Exception('96net.com.cn',10);
}catch(Exception $e){
echo $e->getMessage();
echo $e->getCode();
}

2,自己创建异常类

<?php
class MyException extends Exception{
function demo(){
echo "dc3688.com";
}
}
try{
throw new MyException('96net.com.cn',10);
}catch(Exception $e){
echo $e->getMessage();
echo $e->getCode();
echo $e->demo();
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章