mirror of
https://github.com/danog/parallel.git
synced 2024-11-30 04:39:01 +01:00
Make uncaught exception name available in PanicError
This commit is contained in:
parent
67c82f0f2f
commit
b995524007
@ -3,20 +3,34 @@
|
|||||||
namespace Amp\Parallel;
|
namespace Amp\Parallel;
|
||||||
|
|
||||||
class PanicError extends \Error {
|
class PanicError extends \Error {
|
||||||
|
/** @var string Class name of uncaught exception. */
|
||||||
|
private $name;
|
||||||
|
|
||||||
/** @var string Stack trace of the panic. */
|
/** @var string Stack trace of the panic. */
|
||||||
private $trace;
|
private $trace;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new panic error.
|
* Creates a new panic error.
|
||||||
*
|
*
|
||||||
|
* @param string $name The uncaught exception class.
|
||||||
* @param string $message The panic message.
|
* @param string $message The panic message.
|
||||||
* @param int $code The panic code.
|
* @param int $code The panic code.
|
||||||
* @param string $trace The panic stack trace.
|
* @param string $trace The panic stack trace.
|
||||||
*/
|
*/
|
||||||
public function __construct(string $message = '', int $code = 0, string $trace = '') {
|
public function __construct(string $name, string $message = '', int $code = 0, string $trace = '') {
|
||||||
parent::__construct($message, $code);
|
parent::__construct($message, $code);
|
||||||
|
$this->name = $name;
|
||||||
$this->trace = $trace;
|
$this->trace = $trace;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the class name of the uncaught exception.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getName(): string {
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the stack trace at the point the panic occurred.
|
* Gets the stack trace at the point the panic occurred.
|
||||||
|
@ -18,7 +18,7 @@ class ExitFailure implements ExitStatus {
|
|||||||
private $trace;
|
private $trace;
|
||||||
|
|
||||||
public function __construct(\Throwable $exception) {
|
public function __construct(\Throwable $exception) {
|
||||||
$this->type = get_class($exception);
|
$this->type = \get_class($exception);
|
||||||
$this->message = $exception->getMessage();
|
$this->message = $exception->getMessage();
|
||||||
$this->code = $exception->getCode();
|
$this->code = $exception->getCode();
|
||||||
$this->trace = $exception->getTraceAsString();
|
$this->trace = $exception->getTraceAsString();
|
||||||
@ -29,6 +29,7 @@ class ExitFailure implements ExitStatus {
|
|||||||
*/
|
*/
|
||||||
public function getResult() {
|
public function getResult() {
|
||||||
throw new PanicError(
|
throw new PanicError(
|
||||||
|
$this->type,
|
||||||
\sprintf(
|
\sprintf(
|
||||||
'Uncaught exception in execution context of type "%s" with message "%s"',
|
'Uncaught exception in execution context of type "%s" with message "%s"',
|
||||||
$this->type,
|
$this->type,
|
||||||
|
Loading…
Reference in New Issue
Block a user