PHP Luminova: Exception Classes
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|intreturns the string code if one was set, otherwise the integer code.isCode(string|int|array $code): boolstrictly compares the error code against one value or a list of values.setCode(string|int $code): selfsets the error code.setFile(string $file): selfoverrides the file where the exception is reported.setLine(int $line): selfoverrides the line where the exception is reported.getName(): stringreturns the short readable name of the code, such asDatabase Error.getDescription(): stringreturns the sanitized exception message.getBacktrace(): arrayreturns the exception trace, or the last recorded backtrace when the trace is empty.toString(): stringreturns a one line summary:ClassName: description in file:line (code: code).handle(): voidpasses the exception to the framework error handler.log(?string $dispatch = null): voidwrites 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): voidcreates 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): voidcreates an instance of the called class and passes it to the error handler instead of throwing it.throwAs(Throwable $e, ?string $abstract = null): voidrethrows any throwable as the called class, or as$abstractwhen 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.exceptionsenvironment value is enabled. - In production, non-fatal exceptions are not displayed, but they are still logged.
HttpExceptionterminates the request using its status code and message.- When
debug.display.errorsis 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 = []): voidbuilds the message for the given type, attaches the caller's file and line, and throws.getInformation(string $type, mixed ...$values): stringreturns 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): staticbuilds 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): voidbuilds 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 withErrorCode::WRITE_PERMISSION_DENIED.handleReadFile(string $file, ...)reports a failed file read withErrorCode::READ_PERMISSION_DENIED.handleDirectory(string $path, ...)reports a failed directory creation withErrorCode::CREATE_DIR_FAILED.handlePermission(string $path, ...)reports a failed permission change withErrorCode::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): stringreturns the short name of a code, or its long description when$longistrue. Unknown codes returnUnknown error.has(string|int $severity): boolchecks whether Luminova recognizes the code. Afalseresult does not mean the code is invalid.isFatal(string|int $severity): boolreturnstruefor fatal PHP errors (E_ERROR,E_PARSE,E_CORE_ERROR,E_COMPILE_ERROR,E_USER_ERROR) andErrorCode::CONNECTION_ERROR.getLevel(string|int $severity): stringreturns the log level for a code, defaulting toerror.
use Luminova\Exceptions\ErrorCode;
echo ErrorCode::getName(ErrorCode::DATABASE_ERROR); // Database Error
echo ErrorCode::getName(ErrorCode::DATABASE_ERROR, true); // A database operation failed