Luminova Framework

PHP Luminova: Exception Classes

Last updated: 2026-11-28 20:57:12

Built-in Luminova exception classes, including their namespaces, inheritance, and the conditions they represent.

Luminova Exception classes are a set of built-in exceptions that extend Luminova\Exceptions\LuminovaException to handle different types of unexpected errors and exceptional conditions.

For detailed exception handling guidance, see the Exception Handling documentation.


Class Definition

  • Class namespace: Luminova\Exceptions\*
  • Class implements: Luminova\Interface\ExceptionInterface, \Stringable
  • Class extends: Luminova\Exceptions\LuminovaException, \Exception

For a complete list of built-in exception codes, see the Exception and Error Codes documentation.

All built-in exceptions share the same constructor shape: new Exception(string $message, string|int $code = <default>, ?Throwable $previous = null). Each class below lists its default code. Codes can be integers or strings, and you can pass your own to override the default.


Base Class

Namespace: Luminova\Exceptions\LuminovaException

The abstract base class for every Luminova exception. It extends PHP's \Exception, supports string or integer codes, and adds helpers for inspecting, logging, and handling errors through the framework's error handler. You cannot instantiate it directly, extend it or use one of the built-in classes instead.

Constructor

public function __construct(string $message, string|int $code = 0, ?Throwable $previous = null)

Numeric codes are stored as the native exception code. Non-numeric codes are kept as a string and returned by getErrorCode().

Instance methods

  • getErrorCode(): string|int returns the string code if one was set, otherwise the integer code.
  • isCode(string|int|array $code): bool strictly compares the error code against one value or a list of values.
  • setCode(string|int $code): self sets the error code.
  • setFile(string $file): self overrides the file where the exception is reported.
  • setLine(int $line): self overrides the line where the exception is reported.
  • getName(): string returns the short readable name of the code, such as Database Error.
  • getDescription(): string returns the sanitized exception message.
  • getBacktrace(): array returns the exception trace, or the last recorded backtrace when the trace is empty.
  • toString(): string returns a one line summary: ClassName: description in file:line (code: code).
  • handle(): void passes the exception to the framework error handler.
  • log(?string $dispatch = null): void writes the exception to the application log. The optional argument sets the log level, otherwise the level is resolved from the error code.

Static methods

  • throwException(string $message, string|int $code = 0, ?Throwable $previous = null): void creates an instance of the called class and throws it. The reported file and line point to the caller, or to the previous exception when one is given.
  • handleException(string $message, string|int $code = 0, ?Throwable $previous = null): void creates an instance of the called class and passes it to the error handler instead of throwing it.
  • throwAs(Throwable $e, ?string $abstract = null): void rethrows any throwable as the called class, or as $abstract when it is a valid throwable class. The original message, code, file, and line are preserved.
use Luminova\Exceptions\DatabaseException;

try {
    // ...
} catch (PDOException $e) {
    DatabaseException::throwAs($e);
}

How handle() behaves

  • In CLI, the exception is rethrown when the throw.cli.exceptions environment value is enabled.
  • In production, non-fatal exceptions are not displayed, but they are still logged.
  • HttpException terminates the request using its status code and message.
  • When debug.display.errors is enabled, the exception is printed. Otherwise the framework error page is shown and the exception is logged.

For the full base-class API and usage examples, see Exception Handling.

Common Exceptions

RuntimeException

Namespace: Luminova\Exceptions\RuntimeException

General purpose exception for errors that occur while the application is running. Default code: ErrorCode::RUNTIME_ERROR.

use Luminova\Exceptions\RuntimeException;

throw new RuntimeException(
    'Unable to start the worker process.'
);

LogicException

Namespace: Luminova\Exceptions\LogicException

Thrown for errors in application or implementation logic, such as calling an API in the wrong state. Default code: ErrorCode::LOGIC_ERROR.


InvalidArgumentException

Namespace: Luminova\Exceptions\InvalidArgumentException

Thrown when an argument passed to a method is invalid or out of range. Default code: ErrorCode::INVALID_ARGUMENTS.

use Luminova\Exceptions\InvalidArgumentException;

if ($limit < 1) {
    throw new InvalidArgumentException('Limit must be greater than zero.');
}

InvalidException

Namespace: Luminova\Exceptions\InvalidException

General exception for invalid operations or inputs that do not fit a more specific class. Default code: ErrorCode::INVALID.


InvalidObjectException

Namespace: Luminova\Exceptions\InvalidObjectException

Thrown when a valid object is expected but something else was given. The constructor takes a $key string instead of a message and builds the message itself. Default code: ErrorCode::INVALID.


UnexpectedValueException

Namespace: Luminova\Exceptions\UnexpectedValueException

Thrown when a value is not allowed or does not match what the code expects. Default code: ErrorCode::VALUE_FORBIDDEN.


BadMethodCallException

Namespace: Luminova\Exceptions\BadMethodCallException

Thrown when a callback or method call refers to an undefined method or is made in an invalid context. Default code: ErrorCode::BAD_METHOD_CALL.


NotFoundException

Namespace: Luminova\Exceptions\NotFoundException

Thrown when a required resource or entity cannot be found. Default code: ErrorCode::NOT_FOUND.


ClassException

Namespace: Luminova\Exceptions\ClassException

Thrown when a class name cannot be resolved. The constructor takes the class name as $class instead of a message and builds the message itself. Default code: ErrorCode::CLASS_NOT_FOUND.

use Luminova\Exceptions\ClassException;

throw new ClassException('App\Utils\Missing');

ErrorException

Namespace: Luminova\Exceptions\ErrorException

Represents generic errors, usually PHP errors converted into exceptions. This is Luminova's own class and extends LuminovaException, not PHP's \ErrorException. Default code: ErrorCode::ERROR.

Constructor

public function __construct(
    string $message,
    string|int $code = ErrorCode::ERROR,
    int $severity = 1,
    ?string $filename = null,
    ?int $line = null,
    ?Throwable $previous = null
)

When $filename or $line is provided, it replaces the reported file and line. Use getSeverity(): int to read the severity.


Validation and Security

ValidationException

Namespace: Luminova\Exceptions\ValidationException

Raised when data fails validation checks. Default code: ErrorCode::INPUT_VALIDATION_ERROR.

use Luminova\Exceptions\ValidationException;

throw new ValidationException('Email address is not valid.');

SecurityException

Namespace: Luminova\Exceptions\SecurityException

Indicates a security issue, such as an unauthorized access attempt. Default code: ErrorCode::SECURITY_ISSUE.


EncryptionException

Namespace: Luminova\Exceptions\EncryptionException

Indicates a failure in an encryption or decryption operation. Default code: ErrorCode::CRYPTOGRAPHY_ERROR.


Application and Request Handling

HttpException

Namespace: Luminova\Exceptions\HttpException

Represents an HTTP error response. The exception code holds the HTTP status code, and when the exception is handled, the request is terminated with that status and message.

Constructor

public function __construct(string $message, int $status = 500, ?Throwable $previous = null)

An invalid status code falls back to 500. Use getStatus(): int to read the status code.

use Luminova\Exceptions\HttpException;

throw new HttpException('Page not available.', 503);

RouterException

Namespace: Luminova\Exceptions\RouterException

Represents routing errors, such as invalid namespaces, controllers, middleware usage, or a missing route handler. Default code: ErrorCode::ROUTING_ERROR.

Static methods

  • rethrow(string $type, string|int $code = ErrorCode::ROUTING_ERROR, array $values = []): void builds the message for the given type, attaches the caller's file and line, and throws.
  • getInformation(string $type, mixed ...$values): string returns the formatted message for a type without throwing.

Supported types: argument.empty, invalid.namespace, invalid.namespace.root, invalid.namespace.end, invalid.context, invalid.controller, invalid.request.method, invalid.class, invalid.method, invalid.middleware.cli, invalid.middleware.http, bad.method, no.context, no.route.handler, invalid.cli.group. An unknown type produces a generic routing error message.

use Luminova\Exceptions\RouterException;

RouterException::rethrow('invalid.cli.group', values: ['My Group']);

ViewNotFoundException

Namespace: Luminova\Exceptions\ViewNotFoundException

Thrown when a requested view file cannot be located. Default code: ErrorCode::VIEW_NOT_FOUND.


CookieException

Namespace: Luminova\Exceptions\CookieException

Thrown for invalid cookie names, values, prefixes, or attributes. Default code: ErrorCode::COOKIE_ERROR.

Static method

  • rethrow(string $type, mixed $name = null, string|int $code = ErrorCode::COOKIE_ERROR): static builds the message for the given type, optionally formats it with $name, attaches the caller's file and line, and always throws.

Supported types: invalid_name, empty_name, invalid_secure_prefix, invalid_host_prefix, invalid_same_site, invalid_same_site_none, invalid_value. An unknown type produces a generic cookie error message.

use Luminova\Exceptions\CookieException;

CookieException::rethrow('invalid_name', 'my cookie');

MailerException

Namespace: Luminova\Exceptions\MailerException

Thrown when sending email or preparing a mail client fails. Default code: ErrorCode::MAILER_ERROR.

Static method

  • rethrow(string $type, mixed $name = null, string|int $code = ErrorCode::MAILER_ERROR): void builds the message for the given type, optionally formats it with $name, and always throws.

Supported types: invalid_client, file_access, class_not_exist, no_client. An unknown type produces a generic mailer error message.

use Luminova\Exceptions\MailerException;

MailerException::rethrow('invalid_client', 'MyMailer');

AIAgentException

Namespace: Luminova\Exceptions\AIAgentException

Represents errors raised while processing an AI agent request. Default code: ErrorCode::AI_AGENT_ERROR.


Data, Storage and I/O

DatabaseException

Namespace: Luminova\Exceptions\DatabaseException

General exception for database errors. Default code: ErrorCode::DATABASE_ERROR.


DatabaseLimitException

Namespace: Luminova\Exceptions\DatabaseLimitException

Raised when the database connection limit is exceeded. Default code: ErrorCode::CONNECTION_LIMIT_EXCEEDED.


CacheException

Namespace: Luminova\Exceptions\CacheException

Represents errors in caching operations. Default code: ErrorCode::CACHE_ERROR.


StorageException

Namespace: Luminova\Exceptions\StorageException

Thrown when saving or retrieving stored data fails. Default code: ErrorCode::STORAGE_ERROR.


FileException

Namespace: Luminova\Exceptions\FileException

Thrown when a file system operation fails, such as reading, writing, creating a directory, or changing permissions. Default code: ErrorCode::FILESYSTEM_ERROR.

Static methods

All of these create the exception and pass it to the error handler through handleException(). They do not throw directly. Each method accepts a $message and an optional ?Throwable $previous.

  • handleFile(string $file, ...) reports a failed file write with ErrorCode::WRITE_PERMISSION_DENIED.
  • handleReadFile(string $file, ...) reports a failed file read with ErrorCode::READ_PERMISSION_DENIED.
  • handleDirectory(string $path, ...) reports a failed directory creation with ErrorCode::CREATE_DIR_FAILED.
  • handlePermission(string $path, ...) reports a failed permission change with ErrorCode::SET_PERMISSION_FAILED.
use Luminova\Exceptions\FileException;

FileException::handleReadFile('/path/to/config.json', 'File is not readable.');

IOException

Namespace: Luminova\Exceptions\IOException

Raised when an input/output operation fails. Default code: ErrorCode::IO_ERROR.


JsonException

Namespace: Luminova\Exceptions\JsonException

Thrown when JSON encoding or decoding fails. Default code: ErrorCode::JSON_ERROR.


DateTimeException

Namespace: Luminova\Exceptions\DateTimeException

Thrown when a date or time operation fails. Default code: ErrorCode::DATETIME_ERROR.


Network Exceptions

Namespace group: Luminova\Exceptions\Http\*

These exceptions are for network errors and may be thrown when using the Luminova\Http\Network or HTTP client class. They extend LuminovaException and are separate from HttpException, which represents an HTTP response status.

ClientException

Namespace: Luminova\Exceptions\Http\ClientException

Represents client side errors during HTTP requests, such as 4xx responses. Default code: ErrorCode::HTTP_CLIENT_ERROR.


ServerException

Namespace: Luminova\Exceptions\Http\ServerException

Represents server side errors during HTTP requests, such as 5xx responses. Default code: ErrorCode::HTTP_SERVER_ERROR.


ConnectException

Namespace: Luminova\Exceptions\Http\ConnectException

Thrown when a connection to a remote server cannot be established. Default code: ErrorCode::HTTP_CONNECTION_ERROR.


RequestException

Namespace: Luminova\Exceptions\Http\RequestException

Thrown when an HTTP request cannot be created or processed. Default code: ErrorCode::HTTP_REQUEST_ERROR.


ResponseException

Namespace: Luminova\Exceptions\Http\ResponseException

Thrown when an HTTP response cannot be processed. Default code: ErrorCode::HTTP_RESPONSE_ERROR.


Error Codes

Namespace: Luminova\Exceptions\ErrorCode

Holds the PHP error constants and Luminova's custom, database, and HTTP error codes. It also provides lookup helpers.

  • getName(string|int $severity, bool $long = false): string returns the short name of a code, or its long description when $long is true. Unknown codes return Unknown error.
  • has(string|int $severity): bool checks whether Luminova recognizes the code. A false result does not mean the code is invalid.
  • isFatal(string|int $severity): bool returns true for fatal PHP errors (E_ERROR, E_PARSE, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR) and ErrorCode::CONNECTION_ERROR.
  • getLevel(string|int $severity): string returns the log level for a code, defaulting to error.
use Luminova\Exceptions\ErrorCode;

echo ErrorCode::getName(ErrorCode::DATABASE_ERROR);       // Database Error
echo ErrorCode::getName(ErrorCode::DATABASE_ERROR, true); // A database operation failed