Home >Backend Development >PHP Tutorial >PHP exception handling technology, top exception handler, PHP exception handling_PHP tutorial

PHP exception handling technology, top exception handler, PHP exception handling_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 08:54:24776browse

php exception handling technology, top exception handler, php exception handling

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"); My_expection here 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 will default to it. exception handler to handle exceptions Example: PHP exception handling technology, top exception handler, PHP exception handling_PHP tutorial
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<?<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>?>
PHP exception handling technology, top exception handler, PHP exception handling_PHP tutorial

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1120379.htmlTechArticlephp exception handling technology, top exception handler, php exception handling php handles exceptions the same as java, using The function used to define the top-level exception handler is set_ex...
Statement:
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