phpEZ v0.2.0

NotFoundException extends HTTPException
in package

Exception for missing resources (HTTP 404).

Thrown when an API endpoint or resource cannot be found. Always uses HTTP 404 status code regardless of constructor parameters.

Usage:

if (!$user) {
  NotFoundException::throw(msg: 'user_not_found', more: ['id' => $id]);
}

// Or raise directly:
throw new NotFoundException('post_not_found');
Tags
subpackage

exceptions

Table of Contents

Properties

$more  : mixed

Methods

__construct()  : mixed
Initialize a 404 exception.
throw()  : never
Throw an exception with flexible named arguments.

Properties

Methods

__construct()

Initialize a 404 exception.

public __construct([string $msg = 'not_found' ][, int $_code = 404 ][, Throwable|null $parent = null ][, mixed $more = null ]) : mixed
Parameters
$msg : string = 'not_found'

Error message. Defaults to 'not_found'.

$_code : int = 404

Ignored; always uses 404. Present for API compatibility.

$parent : Throwable|null = null

Previous exception for chaining.

$more : mixed = null

Structured error metadata.

throw()

Throw an exception with flexible named arguments.

public static throw([int|null $code = null ][, string|null $msg = null ][, Throwable|null $parent = null ][, mixed $more = null ]) : never

Static factory method for elegant exception creation. Only non-null arguments are included in the constructor call, allowing clean fluent syntax without positional confusion or needing to pass null for skipped parameters.

Parameters
$code : int|null = null

HTTP status code.

$msg : string|null = null

Error message.

$parent : Throwable|null = null

Previous exception for chaining.

$more : mixed = null

Structured error metadata.

Tags
example
// Minimal
HTTPException::throw(code: 400, msg: 'bad_request');

// With metadata
HTTPException::throw(
  code: 400,
  msg: 'validation_error',
  more: ['field' => 'email', 'reason' => 'already_exists']
);

// With exception chaining
try {
  $pdo->query($sql);
} catch (PDOException $e) {
  HTTPException::throw(code: 500, msg: 'database_error', parent: $e);
}
Return values
never

Always throws the constructed exception.

On this page

Search results