The difference between error and exception in PHP and its application _php tutorial

Source: Internet
Author: User

The difference between error and exception in PHP and its application


This article mainly introduces the difference between error and exception in PHP, and the application, the need for friends can refer to the following

The difference between error and exception check the online data is mostly Java interpretation, it seems that PHP exception processing process and Java almost

The object inheritance structure in Java is as follows:

Object---->throwable--------> Exception----> RuntimeException | Error

Error is unchecked type exception is divided into checked and unchecked types

and treats the anomaly and the error as if the program is not functioning properly.

If you distinguish between exceptions and errors:

Exception: Non-fatal. Try{}catche (Exception e) {} Execution of a try module is a test run, and the code executes an error (Non-fatal error) during Operation Catche

The effect of the 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 ' Connect database error ';

return false;

}

Exceptions can be handled easily using exception handling scenarios. As the following code can handle many exceptions at once

Try

{

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

Other code-want to execute

}catche (Exception $e) {

Print_r ($e);

}

http://www.bkjia.com/PHPjc/852819.html www.bkjia.com true http://www.bkjia.com/PHPjc/852819.html techarticle the difference between error and exception in PHP and its application This article mainly introduces the difference between error and exception in PHP and the application, the need for friends can refer to the difference between the error and the exception check the online funding ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.