PHP set_exception_handler() 函数
PHP 教程
· 2019-01-24 16:11:34
定义和用法
set_exception_handler() 函数设置用户自定义的异常处理函数。
该函数用于创建运行期间的用户自己的异常处理方法。
该函数返回旧的异常处理程序,如果失败则返回 NULL。
语法
set_exception_handler(exception_function)
| 参数 | 描述 |
|---|---|
| exception_function | 必需。规定未捕获的异常发生时调用的函数。 该函数必须在调用 set_exception_handler() 函数之前定义。这个异常处理函数需要需要一个参数,即抛出的 exception 对象。 |
提示和注释
提示:在这个异常处理程序被调用后,脚本会停止执行。
实例
<?php
function myException($exception)
{
echo "<b>Exception:</b> " , $exception->getMessage();
}
set_exception_handler('myException');
throw new Exception('Uncaught Exception occurred');
?>
上面代码的输出如下所示:
Exception: Uncaught Exception occurred
点击查看所有 PHP 教程 文章: https://codercto.com/courses/l/5.html
Think Python
Allen B. Downey / O'Reilly Media / 2012-8-23 / GBP 29.99
Think Python is an introduction to Python programming for students with no programming experience. It starts with the most basic concepts of programming, and is carefully designed to define all terms ......一起来看看 《Think Python》 这本书的介绍吧!