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, after executing the code in try, it executes after the catch.
- 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 ...