| 1 |
<?php |
| 2 |
/** |
| 3 |
* Watchful exception definitions. |
| 4 |
* |
| 5 |
* @version 2016-12-20 11:41 UTC+01 |
| 6 |
* @package watchful |
| 7 |
* @author Watchful |
| 8 |
* @authorUrl https://watchful.net |
| 9 |
* @copyright Copyright (c) 2020 watchful.net |
| 10 |
* @license GNU/GPL |
| 11 |
*/ |
| 12 |
|
| 13 |
namespace Watchful; |
| 14 |
|
| 15 |
use Throwable; |
| 16 |
|
| 17 |
/** |
| 18 |
* Class for Watchful excepction definitions. |
| 19 |
*/ |
| 20 |
class Exception extends \Exception |
| 21 |
{ |
| 22 |
/** |
| 23 |
* Exception data. |
| 24 |
* |
| 25 |
* @var mixed |
| 26 |
*/ |
| 27 |
private $data = null; |
| 28 |
|
| 29 |
/** |
| 30 |
* Constructor for our custom Exceptions. It is compatible with the |
| 31 |
* standard php exceptions as well. |
| 32 |
* |
| 33 |
* @param string $message Either a full message or a short key similar to \WP_Error codes. |
| 34 |
* @param int $code The inherited \Exception code, used as status code for the HTTP response. |
| 35 |
* @param mixed $data Either some data related to the message or a \Throwable for the standard php \Exception. |
| 36 |
*/ |
| 37 |
public function __construct($message = '', $code = 0, $data = null) |
| 38 |
{ |
| 39 |
// Handle php standard format for Exceptions with $previous as 3rd parameter. |
| 40 |
if ($data instanceof \Exception || $data instanceof Throwable) { |
| 41 |
parent::__construct($message, $code, $data); |
| 42 |
} |
| 43 |
|
| 44 |
$this->data = $data; |
| 45 |
parent::__construct($message, $code, null); |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* Get the exception data. |
| 50 |
* |
| 51 |
* @return mixed |
| 52 |
*/ |
| 53 |
public function getData() |
| 54 |
{ |
| 55 |
return $this->data; |
| 56 |
} |
| 57 |
} |
| 58 |
|