Skip to content
Snippets Groups Projects
Commit e8bc5cb4 authored by Olav Morken's avatar Olav Morken
Browse files

Error_Exception: Include the cause of the exception as an parameter.

Including the cause of the exception will make it simpler to trace
exceptions through the program.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1565 44740490-163a-0410-bde0-09ae8108e29a
parent 4730ba86
No related branches found
No related tags found
No related merge requests found
...@@ -22,18 +22,38 @@ class SimpleSAML_Error_Exception extends Exception { ...@@ -22,18 +22,38 @@ class SimpleSAML_Error_Exception extends Exception {
private $backtrace; private $backtrace;
/**
* The cause of this exception.
*
* @var SimpleSAML_Error_Exception
*/
private $cause;
/** /**
* Constructor for this error. * 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.
*
* @param string $message Exception message * @param string $message Exception message
* @param int $code Error code * @param int $code Error code
* @param Exception|NULL $cause The cause of this exception.
*/ */
public function __construct($message, $code = 0) { public function __construct($message, $code = 0, Exception $cause = NULL) {
assert('is_string($message) || is_int($code)'); assert('is_string($message)');
assert('is_int($code)');
parent::__construct($message, $code); parent::__construct($message, $code);
$this->backtrace = SimpleSAML_Utilities::buildBacktrace($this); $this->backtrace = SimpleSAML_Utilities::buildBacktrace($this);
if ($cause !== NULL) {
if (!($cause instanceof SimpleSAML_Error_Exception)) {
$cause = new SimpleSAML_Error_UnserializableException($cause);
}
$this->cause = $cause;
}
} }
...@@ -62,6 +82,16 @@ class SimpleSAML_Error_Exception extends Exception { ...@@ -62,6 +82,16 @@ class SimpleSAML_Error_Exception extends Exception {
} }
/**
* Retrieve the cause of this exception.
*
* @return SimpleSAML_Error_Exception|NULL The cause of this exception.
*/
public function getCause() {
return $this->cause;
}
/** /**
* Function for serialization. * Function for serialization.
* *
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment