Exception.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * @package Kohana/Minion
  4. * @author Kohana Team
  5. * @copyright (c) Kohana Team
  6. * @license https://koseven.ga/LICENSE.md
  7. */
  8. class Kohana_Minion_Exception extends Kohana_Exception {
  9. /**
  10. * Inline exception handler, displays the error message, source of the
  11. * exception, and the stack trace of the error.
  12. *
  13. * Should this display a stack trace? It's useful.
  14. *
  15. * @uses Kohana_Exception::text
  16. * @param Exception $e
  17. * @return boolean
  18. */
  19. public static function handler($e)
  20. {
  21. try
  22. {
  23. // Log the exception
  24. Kohana_Exception::log($e);
  25. if ($e instanceof Minion_Exception)
  26. {
  27. echo $e->format_for_cli();
  28. }
  29. else
  30. {
  31. echo Kohana_Exception::text($e);
  32. }
  33. $exit_code = $e->getCode();
  34. // Never exit "0" after an exception.
  35. if ($exit_code == 0)
  36. {
  37. $exit_code = 1;
  38. }
  39. exit($exit_code);
  40. }
  41. catch (Exception $e)
  42. {
  43. // Clean the output buffer if one exists
  44. ob_get_level() and ob_clean();
  45. // Display the exception text
  46. echo Kohana_Exception::text($e), "\n";
  47. // Exit with an error status
  48. exit(1);
  49. }
  50. }
  51. public function format_for_cli()
  52. {
  53. return Kohana_Exception::text($this);
  54. }
  55. }