<?php
namespace nur\b;

use Error;
use Throwable;

/**
 * Class ExitException: une exception qui indique que l'application souhaite
 * quitter normalement, avec éventuellement un code d'erreur.
 */
class ExitError extends Error {
  function __construct(int $exitcode=0, $userMessage=null, Throwable $previous=null) {
    parent::__construct(null, $exitcode, $previous);
    $this->userMessage = $userMessage;
  }

  function isError(): bool {
    return $this->getCode() !== 0;
  }

  /** @var ?string */
  protected $userMessage;

  function haveMessage(): bool {
    return $this->userMessage !== null;
  }

  function getUserMessage(): ?string {
    return $this->userMessage;
  }
}
