Skip to content

PairException

Viames Marino edited this page Sep 30, 2026 · 2 revisions

Pair framework: PairException

Pair\Exceptions\PairException is the base framework exception type.

Constructor behavior

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

  • logs the previous exception message when present, otherwise the supplied message
  • in Pair 4.1.1, logs CSRF_TOKEN_NOT_FOUND and CSRF_TOKEN_INVALID at notice level, preserving the error code in context; these expected session/token failures do not trigger error snapshots or email/Telegram alerts
  • logs other non-critical errors at error level
  • escalates to CriticalException for critical error codes (DB connection/config/missing DB objects)

Front-end notification helper

PairException::frontEnd(string|Throwable $error): void

Behavior:

  • a Throwable is passed to Logger::exceptionHandler()
  • in production, the displayed message is replaced with translated generic error text
  • outside production, throwable chains provide technical details and string messages use safe localization
  • in headless mode -> JSON error response
  • in web mode -> modal error notification

Implementation example

throw new \Pair\Exceptions\PairException('Invalid state', \Pair\Exceptions\ErrorCodes::GENERIC_ERROR);

Notes

Many framework exceptions extend this class and inherit logging/escalation semantics.

See also: AppException, CriticalException, ApiException, AjaxException.

Clone this wiki locally