Error handling mechanism in PHP

Source: Internet
Author: User
Tags getmessage php error

in PHP, exception handling mechanisms are limited, cannot automatically throw exceptions, must be done manually, and built-in exceptions are limited.

PHP takes a number of exceptions as errors, so that they can be taken over by Set_error_handler as if they were errors, and then actively throwing exceptions.

For example, the following Warning types of errors are not captured: Warning:division by the Zero in

1 Try {2     $a = 5/03 }catch (Exception$e) {4     echo ' error message: ',$e-GetMessage (); 5 }

Use Set_error_handler to take over PHP error handling, catch exceptions and non-fatal errors

1 functionCustomerror ($errno,$errstr,$errfile,$errline){2     Throw New Exception(' Number of error rows '.$errline.‘ Line | '.$errstr);3 }4 Set_error_handler("Customerror",E_all);5 6 Try{7     $a= 5/0;//warning:division by Zero in8}Catch(Exception $e){9     Echo' Error message: ',$e-getMessage ();Ten}

This scenario typically exists in the framework of the custom error handling mechanism, making the experience of error messages more visible.

Error handling mechanism in PHP

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.