| @@ 10-54 (lines=45) @@ | ||
| 7 | * @since 2014/05/05 |
|
| 8 | * @version 0.4 |
|
| 9 | */ |
|
| 10 | class ApplicationException extends \LogicException |
|
| 11 | { |
|
| 12 | /** |
|
| 13 | * @var string エラーメッセージ |
|
| 14 | */ |
|
| 15 | private $errorMessage; |
|
| 16 | ||
| 17 | /** |
|
| 18 | * constructor |
|
| 19 | * @param string $message エラーメッセージ |
|
| 20 | * @param int $code ステータスコード |
|
| 21 | * @param Exception $exception 例外オブジェクト |
|
| 22 | */ |
|
| 23 | public function __construct($message, $code = 500, $exception = null) |
|
| 24 | { |
|
| 25 | parent::__construct($message, $code); |
|
| 26 | ||
| 27 | if ($exception === null) { |
|
| 28 | $exception = $this; |
|
| 29 | } |
|
| 30 | ||
| 31 | if (!empty($message)) { |
|
| 32 | $message .= " "; |
|
| 33 | } |
|
| 34 | ||
| 35 | $this->errorMessage = get_class($exception) . " is thrown: " . $message . $exception->getFile() . "(" . $exception->getLine() . ")"; |
|
| 36 | $stacktraceList = explode("#", $exception->getTraceAsString()); |
|
| 37 | foreach ($stacktraceList as $stacktraceLine) { |
|
| 38 | if ($stacktraceLine === "") { |
|
| 39 | continue; |
|
| 40 | } |
|
| 41 | $this->errorMessage .= PHP_EOL; |
|
| 42 | $this->errorMessage .= "\t#" . trim($stacktraceLine); |
|
| 43 | } |
|
| 44 | } |
|
| 45 | ||
| 46 | /** |
|
| 47 | * エラーメッセージを返却する |
|
| 48 | * @return string エラーメッセージ |
|
| 49 | */ |
|
| 50 | public function getExceptionAsString(): string |
|
| 51 | { |
|
| 52 | return $this->errorMessage; |
|
| 53 | } |
|
| 54 | } |
|
| 55 | ||
| @@ 10-54 (lines=45) @@ | ||
| 7 | * @since 2014/05/05 |
|
| 8 | * @version 0.4 |
|
| 9 | */ |
|
| 10 | class SystemException extends \RuntimeException |
|
| 11 | { |
|
| 12 | /** |
|
| 13 | * @var string エラーメッセージ |
|
| 14 | */ |
|
| 15 | private $errorMessage; |
|
| 16 | ||
| 17 | /** |
|
| 18 | * constructor |
|
| 19 | * @param string $message エラーメッセージ |
|
| 20 | * @param int $code ステータスコード |
|
| 21 | * @param Exception $exception 例外オブジェクト |
|
| 22 | */ |
|
| 23 | public function __construct($message, $code = 500, $exception = null) |
|
| 24 | { |
|
| 25 | parent::__construct($message, $code); |
|
| 26 | ||
| 27 | if ($exception === null) { |
|
| 28 | $exception = $this; |
|
| 29 | } |
|
| 30 | ||
| 31 | if (!empty($message)) { |
|
| 32 | $message .= " "; |
|
| 33 | } |
|
| 34 | ||
| 35 | $this->errorMessage = get_class($exception) . " is thrown: " . $message . $exception->getFile() . "(" . $exception->getLine() . ")"; |
|
| 36 | $stacktraceList = explode("#", $exception->getTraceAsString()); |
|
| 37 | foreach ($stacktraceList as $stacktraceLine) { |
|
| 38 | if ($stacktraceLine === "") { |
|
| 39 | continue; |
|
| 40 | } |
|
| 41 | $this->errorMessage .= PHP_EOL; |
|
| 42 | $this->errorMessage .= "\t#" . trim($stacktraceLine); |
|
| 43 | } |
|
| 44 | } |
|
| 45 | ||
| 46 | /** |
|
| 47 | * エラーメッセージを返却する |
|
| 48 | * @return string エラーメッセージ |
|
| 49 | */ |
|
| 50 | public function getExceptionAsString(): string |
|
| 51 | { |
|
| 52 | return $this->errorMessage; |
|
| 53 | } |
|
| 54 | } |
|
| 55 | ||