1 / 7

Chapter 7

Chapter 7. Error and Exception Handling. basic_exception.php. <? php try { throw new Exception("A terrible error has occurred", 42); } catch (Exception $e) { echo "Exception ". $e-> getCode (). ": ". $e-> getMessage ()."< br />".

matthewd
Download Presentation

Chapter 7

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 7 Error and Exception Handling

  2. basic_exception.php <?php try { throw new Exception("A terrible error has occurred", 42); } catch (Exception $e) { echo "Exception ". $e->getCode(). ": ". $e->getMessage()."<br />". " in ". $e->getFile(). " on line ". $e->getLine(). "<br />"; } ?>

  3. basic_exception.php • http://www.nku.edu/~frank/csc301/Examples/PHP_Exceptions/basic_exception.php

  4. PHP Exception Class • http://www.php.net/manual/en/class.exception.php

  5. User_defined_exception.php <?php class myException extends Exception { function __toString() { return "<table border=\"1\"> <tr> <td><strong>Exception ".$this->getCode()." </strong>: ".$this->getMessage()."<br />"." in ".$this->getFile()." on line ".$this->getLine()." </td> </tr> </table><br />"; } }

  6. User_defined_exception.php try { throw new myException("A terrible error has occurred", 42); } catch (myException $m) { echo $m; } ?>

  7. Bob’s Auto Parts • http://www.nku.edu/~frank/csc301/Examples/PHP_Exceptions/orderform.html • http://www.nku.edu/~frank/csc301/Examples/PHP_Exceptions/processorder_php.pdf • http://www.nku.edu/~frank/csc301/Examples/PHP_Exceptions/file_exception_php.pdf

More Related