cacert-testmgr/manager/library/exception/exception.Base.php

98 lines
2.1 KiB
PHP
Raw Permalink Normal View History

<?php
/**
* @package SLS
* @subpackage EXCEPTION
*/
/**
* extend PHPs standard exception by some details
*
* @package SLS
* @subpackage EXCEPTION
* @author Markus Warg <mw@it-sls.de>
* @since 2009-02-23 16:10
* @version $Id: exception.Base.php 90 2010-03-09 09:48:27Z markus $
*/
class BaseException extends Exception {
2015-08-09 17:12:51 +00:00
/**
* additional data / string
* @var string
*/
protected $extra = '';
/**
* location of thrower
* @var string
*/
protected $exception_location = '';
/**
* make new object
*
2015-08-09 17:12:51 +00:00
* @access public
* @param string $message
* @param int $code
*/
public function __construct($message, $code = 0, $extra = '') {
$bt = debug_backtrace();
2015-08-09 17:12:51 +00:00
$remove_exception = 0;
while( $remove_exception < count($bt) && isset($bt[$remove_exception]['class']) && eregi('exception', $bt[$remove_exception]['class']) ) {
$remove_exception++;
}
2015-08-09 17:12:51 +00:00
if ($remove_exception > 0)
$remove_exception--;
2015-08-09 17:12:51 +00:00
if ($remove_exception < count($bt)) {
$this->exception_location = $bt[$remove_exception]['file'].':'.$bt[$remove_exception]['line'];
}
2015-08-09 17:12:51 +00:00
$this->extra = $extra;
parent::__construct($message,$code);
}
/**
* Make a string out of this exception
2015-08-09 17:12:51 +00:00
*
* @access public
* @return string
*/
2015-08-09 17:12:51 +00:00
public function __toString() {
$out = __CLASS__ . '['.$this->code.']:';
2015-08-09 17:12:51 +00:00
if ($this->exception_location != '')
$out.= $this->exception_location;
$out .= ':';
2015-08-09 17:12:51 +00:00
$out .= " {$this->message}";
2015-08-09 17:12:51 +00:00
if (isset($this->extra) && strlen($this->extra) > 0)
$out .= " ({$this->extra})\n";
return $out;
}
2015-08-09 17:12:51 +00:00
/**
* get the extra info string
*
* @access public
* @return string
*/
public function getExtraInfo() {
return $this->extra;
}
/**
* get the exception location string
*
* @access public
* @return string
*/
public function getExceptionLocation() {
return $this->exception_location;
}
}