nur-sery/nur_src/b/ExitError.php

32 lines
687 B
PHP
Raw Normal View History

2024-04-05 08:31:49 +04:00
<?php
2024-07-16 01:54:30 +04:00
namespace nur\b;
2024-04-05 08:31:49 +04:00
2024-07-16 01:54:30 +04:00
use Error;
2024-04-05 08:31:49 +04:00
use Throwable;
/**
* Class ExitException: une exception qui indique que l'application souhaite
* quitter normalement, avec éventuellement un code d'erreur.
*/
2024-07-16 01:54:30 +04:00
class ExitError extends Error {
2024-05-20 17:35:53 +04:00
function __construct(int $exitcode=0, $userMessage=null, Throwable $previous=null) {
2024-07-16 01:54:30 +04:00
parent::__construct(null, $exitcode, $previous);
$this->userMessage = $userMessage;
2024-04-05 08:31:49 +04:00
}
function isError(): bool {
return $this->getCode() !== 0;
}
2024-07-16 01:54:30 +04:00
/** @var ?string */
protected $userMessage;
2024-04-05 08:31:49 +04:00
function haveMessage(): bool {
2024-07-16 01:54:30 +04:00
return $this->userMessage !== null;
}
function getUserMessage(): ?string {
return $this->userMessage;
2024-04-05 08:31:49 +04:00
}
}