ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
SimpleSAML_Error_Exception Class Reference
+ Inheritance diagram for SimpleSAML_Error_Exception:
+ Collaboration diagram for SimpleSAML_Error_Exception:

Public Member Functions

 __construct ($message, $code=0, Exception $cause=null)
 Constructor for this error. More...
 
 getBacktrace ()
 Retrieve the backtrace. More...
 
 getCause ()
 Retrieve the cause of this exception. More...
 
 getClass ()
 Retrieve the class of this exception. More...
 
 format ($anonymize=false)
 Format this exception for logging. More...
 
 formatBacktrace ($anonymize=false)
 Format the backtrace for logging. More...
 
 log ($default_level)
 Print the exception to the log, by default with log level error. More...
 
 logError ()
 Print the exception to the log with log level error. More...
 
 logWarning ()
 Print the exception to the log with log level warning. More...
 
 logInfo ()
 Print the exception to the log with log level info. More...
 
 logDebug ()
 Print the exception to the log with log level debug. More...
 
 __sleep ()
 Function for serialization. More...
 

Static Public Member Functions

static fromException (Exception $e)
 Convert any exception into a SimpleSAML_Error_Exception. More...
 

Protected Member Functions

 initBacktrace (Exception $exception)
 Load the backtrace from the given exception. More...
 
 logBacktrace ($level=\SimpleSAML\Logger::DEBUG)
 Print the backtrace to the log if the 'debug' option is enabled in the configuration. More...
 

Private Attributes

 $backtrace
 
 $cause
 

Detailed Description

Definition at line 12 of file Exception.php.

Constructor & Destructor Documentation

◆ __construct()

SimpleSAML_Error_Exception::__construct (   $message,
  $code = 0,
Exception  $cause = null 
)

Constructor for this error.

Note that the cause will be converted to a SimpleSAML_Error_UnserializableException unless it is a subclass of SimpleSAML_Error_Exception.

Parameters
string$messageException message
int$codeError code
Exception | null$causeThe cause of this exception.

Definition at line 44 of file Exception.php.

45 {
46 assert('is_string($message)');
47 assert('is_int($code)');
48
49 parent::__construct($message, $code);
50
51 $this->initBacktrace($this);
52
53 if ($cause !== null) {
55 }
56 }
initBacktrace(Exception $exception)
Load the backtrace from the given exception.
Definition: Exception.php:81
static fromException(Exception $e)
Convert any exception into a SimpleSAML_Error_Exception.
Definition: Exception.php:66
$code
Definition: example_050.php:99
catch(Exception $e) $message

References $cause, $code, $message, fromException(), and initBacktrace().

+ Here is the call graph for this function:

Member Function Documentation

◆ __sleep()

SimpleSAML_Error_Exception::__sleep ( )

Function for serialization.

This function builds a list of all variables which should be serialized. It will serialize all variables except the Exception::trace variable.

Returns
array Array with the variables that should be serialized.

Definition at line 304 of file Exception.php.

305 {
306
307 $ret = array_keys((array) $this);
308
309 foreach ($ret as $i => $e) {
310 if ($e === "\0Exception\0trace") {
311 unset($ret[$i]);
312 }
313 }
314
315 return $ret;
316 }
$i
Definition: disco.tpl.php:19
$ret
Definition: parser.php:6

References $i, and $ret.

◆ format()

SimpleSAML_Error_Exception::format (   $anonymize = false)

Format this exception for logging.

Create an array of lines for logging.

Parameters
boolean$anonymizeWhether the resulting messages should be anonymized or not.
Returns
array Log lines that should be written out.

Reimplemented in SimpleSAML_Error_NotFound.

Definition at line 151 of file Exception.php.

152 {
153 $ret = array(
154 $this->getClass().': '.$this->getMessage(),
155 );
156 return array_merge($ret, $this->formatBacktrace($anonymize));
157 }
getClass()
Retrieve the class of this exception.
Definition: Exception.php:136
formatBacktrace($anonymize=false)
Format the backtrace for logging.
Definition: Exception.php:169

References $ret, formatBacktrace(), and getClass().

Referenced by SimpleSAML_Error_Error\saveError().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ formatBacktrace()

SimpleSAML_Error_Exception::formatBacktrace (   $anonymize = false)

Format the backtrace for logging.

Create an array of lines for logging from the backtrace.

Parameters
boolean$anonymizeWhether the resulting messages should be anonymized or not.
Returns
array All lines of the backtrace, properly formatted.

Definition at line 169 of file Exception.php.

170 {
171 $ret = array();
172 $basedir = SimpleSAML_Configuration::getInstance()->getBaseDir();
173
174 $e = $this;
175 do {
176 if ($e !== $this) {
177 $ret[] = 'Caused by: '.$e->getClass().': '.$e->getMessage();
178 }
179 $ret[] = 'Backtrace:';
180
181 $depth = count($e->backtrace);
182 foreach ($e->backtrace as $i => $trace) {
183 if ($anonymize) {
184 $trace = str_replace($basedir, '', $trace);
185 }
186
187 $ret[] = ($depth - $i - 1).' '.$trace;
188 }
189 $e = $e->cause;
190 } while ($e !== null);
191
192 return $ret;
193 }
static getInstance($instancename='simplesaml')
Get a configuration file by its instance name.

References $i, $ret, and SimpleSAML_Configuration\getInstance().

Referenced by format(), and logBacktrace().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fromException()

static SimpleSAML_Error_Exception::fromException ( Exception  $e)
static

Convert any exception into a SimpleSAML_Error_Exception.

Parameters
Exception$eThe exception.
Returns
SimpleSAML_Error_Exception The new exception.

Reimplemented in sspmod_saml_Error.

Definition at line 66 of file Exception.php.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ getBacktrace()

SimpleSAML_Error_Exception::getBacktrace ( )

Retrieve the backtrace.

Returns
array An array where each function call is a single item.

Definition at line 114 of file Exception.php.

115 {
116 return $this->backtrace;
117 }

References $backtrace.

◆ getCause()

SimpleSAML_Error_Exception::getCause ( )

Retrieve the cause of this exception.

Returns
SimpleSAML_Error_Exception|null The cause of this exception.

Definition at line 125 of file Exception.php.

126 {
127 return $this->cause;
128 }

References $cause.

◆ getClass()

SimpleSAML_Error_Exception::getClass ( )

Retrieve the class of this exception.

Returns
string The name of the class.

Reimplemented in SimpleSAML_Error_UnserializableException.

Definition at line 136 of file Exception.php.

137 {
138 return get_class($this);
139 }

Referenced by format(), SimpleSAML_Error_NotFound\format(), logDebug(), logError(), logInfo(), and logWarning().

+ Here is the caller graph for this function:

◆ initBacktrace()

SimpleSAML_Error_Exception::initBacktrace ( Exception  $exception)
protected

Load the backtrace from the given exception.

Parameters
Exception$exceptionThe exception we should fetch the backtrace from.

Definition at line 81 of file Exception.php.

82 {
83
84 $this->backtrace = array();
85
86 // position in the top function on the stack
87 $pos = $exception->getFile().':'.$exception->getLine();
88
89 foreach ($exception->getTrace() as $t) {
90
91 $function = $t['function'];
92 if (array_key_exists('class', $t)) {
93 $function = $t['class'].'::'.$function;
94 }
95
96 $this->backtrace[] = $pos.' ('.$function.')';
97
98 if (array_key_exists('file', $t)) {
99 $pos = $t['file'].':'.$t['line'];
100 } else {
101 $pos = '[builtin]';
102 }
103 }
104
105 $this->backtrace[] = $pos.' (N/A)';
106 }
$function
Definition: cas.php:28

References $function, and $t.

Referenced by __construct(), and SimpleSAML_Error_UnserializableException\__construct().

+ Here is the caller graph for this function:

◆ log()

SimpleSAML_Error_Exception::log (   $default_level)

Print the exception to the log, by default with log level error.

Override to allow errors extending this class to specify the log level themselves.

Parameters
int$default_levelThe log level to use if this method was not overridden.

Definition at line 236 of file Exception.php.

237 {
238 $fn = array(
239 SimpleSAML\Logger::ERR => 'logError',
240 SimpleSAML\Logger::WARNING => 'logWarning',
241 SimpleSAML\Logger::INFO => 'logInfo',
242 SimpleSAML\Logger::DEBUG => 'logDebug',
243 );
244 call_user_func(array($this, $fn[$default_level]), $default_level);
245 }
const DEBUG
Attribute-related utility methods.

References DEBUG.

Referenced by sspmod_saml_IdP_SAML2\handleAuthError().

+ Here is the caller graph for this function:

◆ logBacktrace()

SimpleSAML_Error_Exception::logBacktrace (   $level = \SimpleSAML\Logger::DEBUG)
protected

Print the backtrace to the log if the 'debug' option is enabled in the configuration.

Definition at line 199 of file Exception.php.

200 {
201 // see if debugging is enabled for backtraces
202 $debug = SimpleSAML_Configuration::getInstance()->getArrayize('debug', array('backtraces' => false));
203
204 if (!(in_array('backtraces', $debug, true) // implicitly enabled
205 || (array_key_exists('backtraces', $debug) && $debug['backtraces'] === true) // explicitly set
206 // TODO: deprecate the old style and remove it in 2.0
207 || (array_key_exists(0, $debug) && $debug[0] === true) // old style 'debug' configuration option
208 )) {
209 return;
210 }
211
212 $backtrace = $this->formatBacktrace();
213
214 $callback = array('\SimpleSAML\Logger');
215 $functions = array(
216 \SimpleSAML\Logger::ERR => 'error',
217 \SimpleSAML\Logger::WARNING => 'warning',
218 \SimpleSAML\Logger::INFO => 'info',
219 \SimpleSAML\Logger::DEBUG => 'debug',
220 );
221 $callback[] = $functions[$level];
222
223 foreach ($backtrace as $line) {
224 call_user_func($callback, $line);
225 }
226 }
$debug
Definition: loganalyzer.php:16

References $backtrace, $debug, DEBUG, formatBacktrace(), and SimpleSAML_Configuration\getInstance().

Referenced by logDebug(), logError(), logInfo(), and logWarning().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ logDebug()

SimpleSAML_Error_Exception::logDebug ( )

Print the exception to the log with log level debug.

This function will write this exception to the log, including a full backtrace.

Definition at line 289 of file Exception.php.

290 {
291 SimpleSAML\Logger::debug($this->getClass().': '.$this->getMessage());
293 }
static debug($string)
Definition: Logger.php:213
logBacktrace($level=\SimpleSAML\Logger::DEBUG)
Print the backtrace to the log if the 'debug' option is enabled in the configuration.
Definition: Exception.php:199

References SimpleSAML\Logger\debug(), DEBUG, getClass(), and logBacktrace().

+ Here is the call graph for this function:

◆ logError()

SimpleSAML_Error_Exception::logError ( )

Print the exception to the log with log level error.

This function will write this exception to the log, including a full backtrace.

Definition at line 253 of file Exception.php.

254 {
255 SimpleSAML\Logger::error($this->getClass().': '.$this->getMessage());
256 $this->logBacktrace(\SimpleSAML\Logger::ERR);
257 }
static error($string)
Definition: Logger.php:168

References SimpleSAML\Logger\error(), getClass(), and logBacktrace().

Referenced by SimpleSAML_Error_Error\show().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ logInfo()

SimpleSAML_Error_Exception::logInfo ( )

Print the exception to the log with log level info.

This function will write this exception to the log, including a full backtrace.

Definition at line 277 of file Exception.php.

278 {
279 SimpleSAML\Logger::info($this->getClass().': '.$this->getMessage());
280 $this->logBacktrace(\SimpleSAML\Logger::INFO);
281 }
static info($string)
Definition: Logger.php:201

References getClass(), SimpleSAML\Logger\info(), and logBacktrace().

+ Here is the call graph for this function:

◆ logWarning()

SimpleSAML_Error_Exception::logWarning ( )

Print the exception to the log with log level warning.

This function will write this exception to the log, including a full backtrace.

Definition at line 265 of file Exception.php.

266 {
267 SimpleSAML\Logger::warning($this->getClass().': '.$this->getMessage());
268 $this->logBacktrace(\SimpleSAML\Logger::WARNING);
269 }
static warning($string)
Definition: Logger.php:179

References getClass(), logBacktrace(), and SimpleSAML\Logger\warning().

+ Here is the call graph for this function:

Field Documentation

◆ $backtrace

SimpleSAML_Error_Exception::$backtrace
private

Definition at line 23 of file Exception.php.

Referenced by getBacktrace(), and logBacktrace().

◆ $cause


The documentation for this class was generated from the following file: