php异常处理技术,顶级异常处理器
定义顶级异常处理器用到的函数是
set_exception_handler("My_exception");
这里的My_expection是开发者自定义的异常处理函数,既顶级异常处理器,只有当程序中没有函数来处理异常才有顶级异常处理器来处理异常,如果没有定义顶级异常处理器,则由系统默认的异常处理器来处理异常
举例说明:
复制代码 代码如下:
set_exception_handler("My_expection");
function My_expection(){
echo "这里是顶级异常处理器";
}
try{
nohello("hello");
}catch(Exception $e){
throw $e;
}
function nohello($nohello){
if($nohello == "hello"){
throw new Exception("不能输入hello");
}else{
echo "输入成功";
}
}
?>
关于PHP异常处理 的一个问题
复制代码 代码如下:
try {
$a=10/0;
}catch (Exception $e){
echo "抛出异常";
}
?>
以上代码,并不会输出“抛出异常”,而是输出了错误信息:Warning: Division by zero in......
说明:try块中并没有抛出异常,而是按照系统默认的错误处理机制进行处理
所以能不能捕获到异常,取决于有没有真正的抛出异常

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.
