Skip to content

CriticalException

Viames Marino edited this page Feb 23, 2026 · 1 revision

Pair framework: CriticalException

Pair\Exceptions\CriticalException handles fatal framework/application failures.

Constructor behavior

__construct(string $message, int $code = 0, ?Throwable $previous = null):

  • logs emergency-level error
  • terminates app through CriticalException::terminate(...)

Termination flow

terminate(string $message, int $code = 0): void

  • sets HTTP 500
  • disables logger for env-file loading failures
  • in headless mode: stops without rendering HTML
  • in web mode: clears buffer, resolves fallback template, renders via TemplateRenderer

Fallback template resolution

Internal fallback search in templates:

  1. 500.php
  2. default.php

If no template exists, execution stops with fatal message.

Implementation example

use Pair\Exceptions\CriticalException;
use Pair\Exceptions\ErrorCodes;

throw new CriticalException('Configuration file missing', ErrorCodes::LOADING_ENV_FILE);

See also: PairException, TemplateRenderer, ErrorCodes.

Clone this wiki locally