errException.php 1.2 KB
<?php

static $oldErrHandler = NULL;

class errException extends Exception
{
	protected $errContext;

	function __construct ($msg, $no, $file, $line, $context)
	{
		parent::__construct ($msg, $no);

		$this->file = $file;
		$this->line = $line;
		$this->errContext = $context;
	}

	function __toString ()
	{
		$retStr  = "Laufzeitfehler (" . $this->code . "): \n";
		$retStr .= $this->message . "\n\n";
		$retStr .= 'Datei: ' . $this->file . "\n";
		$retStr .= 'Zeile: ' . $this->line . "\n";

		if ($this->errContext != NULL)
		{
			$retStr .= "Fehler Context: \n";
			$retStr .= print_r ($this->errContext, TRUE) . "\n";
		}

		$retStr .= "Aufruf Stack: \n";
		$retStr .= $this->getTraceAsString () . "\n";

		return $retStr;
	}

	function getErrContext ()
	{
		return $this->errContext;
	}
}

function mapErrToExc ($no, $msg, $file, $line, $con)
{
	throw new errException ($msg, $no, $file, $line, $con);
}

function setErrExceptionMapping ()
{
	global $oldErrHandler;

	if ($oldErrHandler == NULL)
		$oldErrHandler = set_error_handler ('mapErrToExc');
}

function resetErrExceptionMapping ()
{
	global $oldErrHandler;

	if ($oldErrHandler != NULL)
	{
		set_error_handler ($oldErrHandler);
		$oldErrHandler = NULL;
	}
}

?>