PHP 异常处理

来源:互联网 发布:java调用kettle 编辑:程序博客网 时间:2024/05/18 01:29
<?php//创建可抛出一个异常的函数function checkNum($number){if($number>1){throw new Exception("Value must be 1 or below" , "666666");}return true; }/*//在 "try" 代码块中触发异常try{ checkNum(2); //If the exception is thrown, this text will not be shown echo 'If you see this, the number is 1 or below'; }catch(Exception $e){ echo 'Message: ' .$e->getMessage(); echo "code" . $e->getcode(); echo "line" . $e->getline(); } */   function myException( $e ){ echo 'Message: ' .$e->getMessage().'||'."code" . $e->getcode()."||"."line" . $e->getline(); } // 设置用户定义的异常处理函数 set_exception_handler("myException"); checkNum(2);?>

0 0
原创粉丝点击