PHP exception handling technology, top exception handler PHP custom exception c# exception handling java exception handling

WBOY
Release: 2016-07-29 08:53:29
Original
1244 people have browsed it

php handles exceptions the same as java, using try{}catch(){}

The function used to define the top-level exception handler is

set_exception_handler("My_exception");

here My_expection is a developer-defined exception handling function, which is a top-level exception handler. Only when there is no function in the program to handle exceptions will there be a top-level exception handler to handle exceptions. If no top-level exception handler is defined, the system defaults to it. Exception handler to handle exceptions

Example:

php 异常处理机制,php 错误处理 异常,php 异常处理,php 异常,php 错误 异常 区别,php 自定义异常,c# 异常处理,java 异常处

<meta http-equiv="content-type" c />
Copy after login
<?<span>php
    </span><span>set_exception_handler</span>("My_expection"<span>);
    </span><span>function</span><span> My_expection(){
        </span><span>echo</span> "这里是顶级异常处理器"<span>;
    }
    </span><span>try</span><span>{
        nohello(</span>"hello"<span>);
    }</span><span>catch</span>(<span>Exception</span><span>$e</span><span>){
        </span><span>throw</span><span>$e</span><span>;
    }
  </span><span>function</span> nohello(<span>$nohello</span><span>){
          </span><span>if</span>(<span>$nohello</span> == "hello"<span>){
              </span><span>throw</span><span>new</span><span>Exception</span>("不能输入hello"<span>);
          }</span><span>else</span><span>{
            </span><span>echo</span> "输入成功"<span>;
        }
    }
</span>?>
Copy after login

php 异常处理机制,php 错误处理 异常,php 异常处理,php 异常,php 错误 异常 区别,php 自定义异常,c# 异常处理,java 异常处

Reprinted from: http://blog.sina.com.cn/s/blog_641d5693010121cr.html

The above introduces PHP exception handling technology, the top exception handler, including exception handling, PHP content, I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template