1、Exception类
PHP的异常处理中提供了内置类—Exception,其构造函数需要两个参数,一个错误消息和一个错误代码。
getCode() —返回传递给构造函数的代码 getMessage() — 返回传递给构造函数的消息 getFile() —返回产生异常的代码文件的完整路径 getLine() —返回代码文件中产生异常的代码行号 getTrace() —返回一个包含了产生异常的代码回退路径的数组
<?php
try{
throw new Exception('A terrible error has occurred',42);
}
catch (Exception $e){
echo "Exception".$e->getCode().$e->getMessage()."<br />".
in .$e->getFile(). on line $e->getLine(). "<br />";
}
?>
转载请注明原文地址: https://ju.6miu.com/read-13356.html