[php]php error handling mechanism

Source: Internet
Author: User
Tags php error

Tag:des   io   ar   on    file    cti    line   sql   br   

1. Determine if the file exists,
File_exists ("file name") or Die ("No such file");
2, Set_error_hanlder ("Error handling function name", error constant);
Generally used to handle various errors in the system
This is a callback function that can invoke a custom error handler.
A custom function can accept at least two parameters with a maximum of five parameters,
Basic syntax:
Error_function (Error_level, Error_message, Error_file, Error_line, Error_context);
Cases:
<?php
function My_error ($errLevel, $errDescribe)//An error level, a description of the error
{
echo "Level:"
}
Set_error_hanlder ("Mysql_error", e_warning);
?>
3. Error Trigger
tend to handle logical errors,
<?php
if (age>30)
{
Trigger_error ("too old");
}
?>
4. Abnormal
Exceptions require the use of custom top-level exception handlers or Try-catch to handle
You can also customize the exception class to inherit extends Exception
<?php
Funcction my_exception ($exception)
{
echo "Top exception handler". $exception->getmessage ();
}
To modify the default top-level exception handling function
Set_exception_handler ("My_exception");
?>

[php]php error handling mechanism

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.