Source of file AmqpAgentException.php
Size: 3,494 Bytes - Last Modified: 2021-01-12T22:04:13+00:00
C:/Users/MAKS/Code/_PROJECTS/amqp-agent/src/Exception/AmqpAgentException.php
12345678910111213141516171819202122232425262728293031
Covered by 42 test(s):
32
Covered by 42 test(s):
3334353637383940
Covered by 1 test(s):
41424344454647484950515253
Covered by 14 test(s):
54
Covered by 7 test(s):
55
Covered by 7 test(s):
56
Covered by 7 test(s):
57
Covered by 7 test(s):
5859
Covered by 7 test(s):
606162
Covered by 14 test(s):
6364
Covered by 1 test(s):
65
Covered by 1 test(s):
66
Covered by 1 test(s):
676869
Covered by 13 test(s):
70
Covered by 5 test(s):
71
Covered by 14 test(s):
727374
Covered by 14 test(s):
7576777879808182838485868788
Covered by 1 test(s):
899091
| <?php /** * @author Marwan Al-Soltany <MarwanAlsoltany@gmail.com> * @copyright Marwan Al-Soltany 2020 * For the full copyright and license information, please view * the LICENSE file that was distributed with this source code. */ declare(strict_types=1); namespace MAKS\AmqpAgent\Exception; use Exception as CoreException; use MAKS\AmqpAgent\Helper\Utility; /** * AMQP Agent base exception class. * @since 1.0.0 */ class AmqpAgentException extends CoreException { /** * Redefine the exception so message is not an optional parameter. * @param string $message * @param int $code * @param CoreException|null $previous */ public function __construct(string $message, int $code = 0, CoreException $previous = null) { parent::__construct($message, $code, $previous); } /** * String representation of the object. * @return string */ public function __toString() { return static::class . ": [{$this->code}]: {$this->message}\n{$this->getTraceAsString()}\n"; } /** * Rethrows an exception with an additional message. * @param CoreException $exception The exception to rethrow. * @param string|null $message [optional] An additional message to add to the wrapping exception before the message of the passed exception. * @param string|bool $wrap [optional] Whether to throw the exception using the passed class (FQN), in the same exception type (true), or wrap it with the class this method was called on (false). Any other value will be translated to false. Defaults to true. * @return void * @throws CoreException */ public static function rethrow(CoreException $exception, ?string $message = null, $wrap = true): void { if (null === $message) { $trace = Utility::backtrace(['file', 'line', 'class', 'function']); $prefix = (isset($trace['class']) ? "{$trace['class']}::" : "{$trace['file']}({$trace['line']}): "); $suffix = "{$trace['function']}() failed!"; $message = 'Rethrown Exception: ' . $prefix . $suffix . ' '; } else { $message = strlen($message) ? $message . ' ' : $message; } $error = is_string($wrap) ? ( class_exists($wrap) && is_subclass_of($wrap, 'Exception') ? $wrap : static::class ) : ( boolval($wrap) ? get_class($exception) : static::class ); throw new $error($message . (string)$exception->getMessage(), (int)$exception->getCode(), $exception); } /** * Rethrows an exception with an additional message. * @deprecated 1.2.0 Use `self::rethrow()` instead. * @param CoreException $exception The exception to rethrow. * @param string|null $message [optional] An additional message to add to the wrapping exception before the message of the passed exception. * @param string|bool $wrap [optional] Whether to throw the exception using the passed class (FQN), in the same exception type (true), or wrap it with the class this method was called on (false). Any other value will be translated to false. * @return void * @throws CoreException */ public static function rethrowException(CoreException $exception, ?string $message = null, $wrap = true): void { static::rethrow($exception, $message, $wrap); } } |