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.

57 lines
2.1 KiB

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