- classcustomExceptionextends Exception{
- public function errorMessage(){
- $error_message= "文件".$this->getFile()."的第".$this->getLine()."行发生了错误,错误详情:".$this->getMessage()."
- ";
- return $error_message;
- }
- }
- $number= 2;
- try{
- if($number> 1){
- throw newcustomException('所输入的值不能大于1');//文件E:\www\test\admin.php的第12行发生了错误,错误详情:所输入的值不能大于1
- }
- echo'如果程序运行到了这儿,说明输入的数字<=1';
- }
- catch(customException$e){
- echo $e->errorMessage();
- }
来源: