Home >Backend Development >PHP Tutorial >The difference and application of error and exception in php_PHP tutorial

The difference and application of error and exception in php_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:21:50828browse

The difference and application of error and exception in php

This article mainly introduces the difference and application of error and exception in php. Friends in need can refer to it

The difference between error and exception. Most of the online information is explained by Java. It seems that the exception handling process of PHP is similar to that of Java

The Object inheritance structure in java is as follows:

 Object---->Throwable--------> Exception ----> RuntimeException | Error

Errors are all unchecked types. Exceptions are divided into checked and unchecked types

And treat exceptions and errors as symptoms of abnormal program operation

If you distinguish between exceptions and errors:

Anomaly: Non-fatal. try{}catche(Exception e){} The try module being executed is a test run. If an error (non-fatal error) occurs during the running of the code, execute catch

The function of exception is similar to the following code:

 if(mysql_connect('127.0.0.1','root','321321'))

 {

echo 'Connect to database successfully';

// other code...

 }

else

 {

echo 'Error connecting to database';

return false;

 }

Using exception handling can easily handle exceptions. For example, the following code can handle many exceptions at once

try

 {

mysql_connect('127.0.0.1','root','321321');

// other code you want to execute

 }catch(Exception $e){

print_r($e);

 }

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/852819.htmlTechArticleThe difference and application of error and exception in php This article mainly introduces the difference and application of error and exception in php , friends in need can refer to the difference between error and exception to check online information...
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