summaryrefslogtreecommitdiff
blob: 82f612262dd928a532633fd7118abb9be2011eda (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
function exception_handler($e) {
	global $death;
	$trace=array();
	foreach ($e->getTrace() as $t) {
		$trace[]='<b>'.$t['function'].'</b>(<b>'.htmlentities(implode(', ', $t['args'])).'</b>) at <b>'.$t['file'].'</b> line <b>'.$t['line'].'</b><br/>';
	}
	$trace=implode(' from<br/>', $trace);
	$death.=print_error('Uncaught '.get_class($e).': '.$e->getMessage(), 'Thrown at:<br/>'.$trace);
}
set_exception_handler('exception_handler');
// Directly copied from PHP Manual -> Language Reference -> Predefined Exceptions -> ErrorException
function exception_error_handler($errno, $errstr, $errfile, $errline ) {
	if ((error_reporting() & $errno) == 0) { // Don't report errors that aren't supposed to be reported
		return;
	}
	global $death;
	$errtypes=array(
		E_ERROR => 'Fatal Error',
		E_WARNING => 'Warning',
		E_PARSE => 'Parse Error',
		E_NOTICE => 'Notice',
		E_CORE_ERROR => 'Fatal Core Error',
		E_CORE_WARNING => 'Core Warning',
		E_COMPILE_ERROR => 'Fatal Compile-Time Error',
		E_COMPILE_WARNING => 'Compile-Time Warning',
		E_USER_ERROR => 'Fatal User Error',
		E_USER_WARNING => 'User Warning',
		E_USER_NOTICE => 'User Notice',
		E_STRICT => 'Strict Message',
		E_RECOVERABLE_ERROR => 'Recoverable Fatal Error'/*,
		// PHP 5.3.0:
		E_DEPRECATED => 'Deprecation Notice',
		E_USER_DEPRECATED => 'User Deprecation Notice'
		*/
	);
	if (isset($errtypes[$errno])) {
		$type=$errtypes[$errno];
	} else {
		$type='Unknown Error';
	}
	$trace='';
	foreach (debug_backtrace() as $t) {
		if (!isset($first)) {
			$first=false;
			continue;
		}
		if (isset($t['args'])) {
			foreach ($t['args'] as $i => $arg) {
				if (!is_scalar($arg)) {
					$t['args'][$i]=var_export($arg, true);
				}
			}
		}
		$trace.='from <b>'.(isset($t['function'])?(isset($t['class'])?$t['class'].$t['type']:'').$t['function'].'</b>'.(isset($t['args'])?'(<b>'.htmlentities(implode(', ', $t['args'])).'</b>)':''):(isset($t['args'])?'Included file(s) '.implode(', ', $t['args']):'')).(isset($t['file'])?' at <b>'.$t['file'].'</b>'.(isset($t['line'])?' line <b>'.$t['line'].'</b>':''):'').'<br/>';
	}
	$death.=print_error($type, $errstr.'<br/>'.$trace);
}
set_error_handler("exception_error_handler");
?>