标签:
<?php
try
{
throw new exception(‘发生错误!‘, 42);
}
catch (exception $e)
{
echo ‘编号 ‘ .$e->getCode().‘ :‘ .$e->getMessage();
}
?>
PHP 5中提供了exception异常类,该类除了构造函数外,还提供了一些内置方法:
<?php
class MyException extends exception
{
function _toString()
{
return ‘<table><tr><td>Exception ‘ .$this->getCode().
‘ :‘ .$this->getMessage(). ‘<br />in ‘ .$this->getFile().
‘ on line ‘ .$this->getLine(). ‘</td></tr></table>‘;
}
}
try
{
throw new MyException(‘出错啦!‘, 42);
}
catch(MyException $e)
{
echo $e; // 自动调用 _toString() 方法。
}
?>
标签:
原文地址:http://www.cnblogs.com/csharphuang/p/4241621.html