reenadak

exception handling in php

Sep 25th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4. function md_require($file){
  5. if(file_exists($file)) {
  6. require_once($file);
  7. } else {
  8. throw(new Exception('File '.$file.' does not exist.'));
  9. }
  10. }
  11.  
  12. md_require("config.php");
  13.  
  14. echo "This is a test file";
  15. */
  16.  
  17. try {
  18. $error = 'Always throw this error';
  19. throw new Exception($error);
  20.  
  21. // Code following an exception is not executed.
  22. echo 'Never executed';
  23.  
  24. } catch (Exception $e) {
  25. echo 'Caught exception: ', $e->getMessage(), "\n";
  26. }
  27.  
  28. // Continue execution
  29. echo 'Hello World';
  30. ?>
Add Comment
Please, Sign In to add comment