* @link * @package Majestic * @subpackage Core * @since * @version SVN: $Id$ * @filesource $URL$ */ class MJException extends Exception { private $line_range = 6; public function terminate() { if (!DEBUG_ENABLE) { trigger_error($this->getMessage()); throw new StaticPageException(500); } $return = "MJ Error: "; $return .= str_replace("\n", "
\n", $this->getMessage())."
\n"; $trace = $this->getTrace(); $file = reset($trace); //смещение в трейсе, указаное при вызове эксепшена (2й параметр). Нужно для более инофрмативного вывода if ($shift = abs($this->getCode())) { while($shift--) { $file = next($trace); } } if ($fp = fopen($file['file'], 'r')) { $error_line = $file['line']; $start = $error_line - $this->line_range; $end = $error_line + $this->line_range; $i = 1; $return .= "
";
            while ($line = fgets($fp, 4096) and $i<=$end) {
                $line = htmlspecialchars($line);
                if ($i >= $start && $i <= $end) {
                    if ($i == $error_line) $return .= '
'.$i.' '.$line.'
'; else $return .= $i.' '.$line; } $i++; } $return .= "
"; fclose($fp); } $return .= ''; $return .= "\n'; foreach($trace as $row) { if (isset($row['file'])) { //throwing exception from __call method will not return file and line $return .= "\n'; } } return $return . '
Backtrace
".$this->getFile().''.$this->getLine().'
".$row['file'].''.$row['line'].'
'; } } ?>