You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
2.3 KiB

  1. <?php
  2. /**
  3. * Обработчик эксепшенов
  4. *
  5. * @copyright NetMonsters <team@netmonsters.ru>
  6. * @link
  7. * @package Majestic
  8. * @subpackage Core
  9. * @since
  10. * @version SVN: $Id$
  11. * @filesource $URL$
  12. */
  13. class MJException extends Exception
  14. {
  15. private $line_range = 6;
  16. public function terminate()
  17. {
  18. if (!DEBUG_ENABLE) {
  19. trigger_error($this->getMessage());
  20. throw new StaticPageException(500);
  21. }
  22. $return = "<b>MJ Error:</b> ";
  23. $return .= str_replace("\n", "<br/>\n", $this->getMessage())."<br>\n";
  24. $trace = $this->getTrace();
  25. $file = reset($trace);
  26. //смещение в трейсе, указаное при вызове эксепшена (2й параметр). Нужно для более инофрмативного вывода
  27. if ($shift = abs($this->getCode())) {
  28. while($shift--) {
  29. $file = next($trace);
  30. }
  31. }
  32. if ($fp = fopen($file['file'], 'r')) {
  33. $error_line = $file['line'];
  34. $start = $error_line - $this->line_range;
  35. $end = $error_line + $this->line_range;
  36. $i = 1;
  37. $return .= "<pre style=\"background-color:#e4e4e4\">";
  38. while ($line = fgets($fp, 4096) and $i<=$end) {
  39. $line = htmlspecialchars($line);
  40. if ($i >= $start && $i <= $end) {
  41. if ($i == $error_line) $return .= '<div style="background-color:#cccccc">'.$i.' '.$line.'</div>';
  42. else $return .= $i.' '.$line;
  43. }
  44. $i++;
  45. }
  46. $return .= "</pre>";
  47. fclose($fp);
  48. }
  49. $return .= '<table border="1" cellpadding="2" cellspacing="0"> <caption><b>Backtrace</b></caption>';
  50. $return .= "\n<tr><td><b>".$this->getFile().'</b></td><td><b>'.$this->getLine().'</b></td></tr>';
  51. foreach($trace as $row) {
  52. if (isset($row['file'])) { //throwing exception from __call method will not return file and line
  53. $return .= "\n<tr".($file['file'] == $row['file'] ? ' style="background-color:#ffcccc"': '')."><td>".$row['file'].'</td><td>'.$row['line'].'</td></tr>';
  54. }
  55. }
  56. return $return . '</table>';
  57. }
  58. }
  59. ?>