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

时间:2019-12-18 09:36:32   收藏:0   阅读:76
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();
}

原文:https://blog.51cto.com/13959155/2459333

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!