时间:2021-07-01 10:21:17 帮助过:17人阅读
代码如下:
if(){
}else{
}
try {
}catch(异常对象){
}
代码如下:
class OpenFileException extends Exception {
function __construct($message = null, $code = 0){
parent::__construct($message, $code);
echo "wwwwwwwwwwwwwww
";
}
function open(){
touch("tmp.txt");
$file=fopen("tmp.txt", "r");
return $file;
}
}
class DemoException extends Exception {
function pro(){
echo "处理demo发生的异常
";
}
}
class TestException extends Exception {
function pro(){
echo "这里处理test发生的异常
";
}
}
class HelloException extends Exception {
}
class MyClass {
function openfile(){
$file=@fopen("tmp.txt", "r");
if(!$file)
throw new OpenFileException("文件打开失败");
}
function demo($num=0){
if($num==1)
throw new DemoException("演示出异常");
}
function test($num=0){
if($num==1)
throw new TestException("测试出错");
}
function fun($num=0){
if($num==1)
throw new HelloException("###########");
}
}
try{
echo "11111111111111
";
$my=new MyClass();
$my->openfile();
$my->demo(0);
$my->test(0);
$my->fun(1);
echo "22222222222222222
";
}catch(OpenFileException $e){ //$e =new Exception();
echo $e->getMessage()."
";
$file=$e->open();
}catch(DemoException $e){
echo $e->getMessage()."
";
$e->pro();
}catch(TestException $e){
echo $e->getMessage()."
";
$e->pro();
}catch(Exception $e){
echo $e->getMessage()."
";
}
var_dump($file);
echo "444444444444444444444
";
以上就介绍了异地违章怎么处理 php错误、异常处理机制补充,包括了异地违章怎么处理方面的内容,希望对PHP教程有兴趣的朋友有所帮助。