php学习--自定义错误处理

+展开
-PHP
<?php
/*//所有错误的基类Exception
class Exception{
protected $message="Unknown exception",$code=0,$file,$line,$trace,$string;
function __construct(string $message=null,int $code=0){
if(func_num_args())$this->message=$message;
$this->code=$code;
$this->file=__FILE__;//of throw clause
$this->line=__LINE__;//of throw clause
$this->trace=debug_backtrace();
$this->string=StringFormat($this);
}
final function getMessage(){
return $this->message;
}
final function getCode(){
return $this->code;
}
final function getFile(){
return $this->file;
}
final function getTrace(){
return $this->trace;
}
final function getTraceAsString(){

}
function __toString(){
return $this->string;
}
static private function StringFormat(Exception $exception){
//函数体,这里不作介绍
}
static private function TraceFormat(Exception $exception){
//函数体,这里不作介绍
}
}
*/


class selfError extends exception{
function __tostring(){
return $this->getFile()."<自定义错误!<br/>Line:".$this->getLine()."<br/>Code:".$this->getCode();
}
}

try
{
throw new selfError("错误",168);
}
catch(selfError $e)
{echo $e;}
?>

加支付宝好友偷能量挖...


原创文章,转载请注明出处:php学习--自定义错误处理

评论(0)Web开发网
阅读(93)喜欢(0)PHP/apache/Perl