The difference and application of error and exception in PHP

Source: Internet
Author: User
Tags exception handling php and php exception handling

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

The difference between error and exception access to the online data is mostly Java explanation, seemingly PHP exception handling process and Java almost

The object inheritance structure in Java is as follows:

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

Error is unchecked type exception divided into checked and unchecked types

And to treat the anomalies and errors as the process of abnormal operation of the phenomenon to see

If you distinguish between exceptions and errors:

Exception: Not fatal. Try{}catche (Exception e) {} The Try module in execution is a test run that has an error (non-fatal error) executing during the run of the Code Catche

The exception works like the following code:

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

{

echo ' Connect to database success ';

Other code ...

}

Else

{

Echo ' Connection database error ';

return false;

}

Exceptions can be handled easily by using exception handling. As the following code can handle a lot of exceptions at once

Try

{

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

Other code for you want to execute

}catche (Exception $e) {

Print_r ($e);

}

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.