PHP exception and error handling _php tutorial

Source: Internet
Author: User
Exception handling: Accidents are unexpected things that occur during the course of a program, using exceptions to change the script's normal flow.

Try{}catch (Exception object) {}
    1. If the code in try is not a problem, after executing the code in try, it executes after the catch.
    2. If the code in the try has an exception, throws an exception object, throws it to the object in the catch, then the code in the try is no longer executed, jumps directly into the catch to execute, execution completes in the catch, and continues down execution.

NOTE: The hint is what happened, not what we do primarily, we need to fix this exception in catch and throw it to the user if it can't be solved.

 
  ";    }} Class myclass{    function OpenFile () {        $file = @fopen ("Aaa.txt", "R");        if (! $file)            throw new Openfileexception ("File open Failed");    }        Function demo ($num =0) {        if ($num ==1)            throw new Demoexception ("Demo exception!");}    } try{    $my =new MyClass ();    $my->openfile ();    $my->demo ("1");} catch (Openfileexception $e) {    echo $e->getmessage (). "
"; $file = $e->open ();} catch (Demoexception $e) { echo $e->getmessage (). "
"; $e->pro ();} catch (Exception $e) { //Receive all exceptions thrown but not processed echo $e->getmessage ();}? >

Error handling: 1. Syntax error 2. Runtime error 3. Logic error

Error Report: Error: E_error warning: e_warning Note: e_notice

Recommendation: Development phase: Development is the output of all error reports, in favor of debugging programs. Run phase: Do not let the program output any kind of error reporting.

 
  

http://www.bkjia.com/PHPjc/752516.html www.bkjia.com true http://www.bkjia.com/PHPjc/752516.html techarticle exception Handling: Accidents are unexpected things that occur during the course of a program, using exceptions to change the script's normal flow. Try{}catch (Exception object) {} if the code in try is not a problem, then ...

  • 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.