DuplicateException
extends DataException
in package
Exception for database constraint violations (e.g., unique, foreign key).
Thrown for duplicate key or similar constraint violations. Returns HTTP 400 (bad request) instead of 500 since it's typically a client input issue.
Tags
Table of Contents
Properties
- $more : mixed
Methods
- __construct() : mixed
- Initialize a duplicate constraint exception.
- throw() : never
- Throw an exception with flexible named arguments.
Properties
$more read-only
public
mixed
$more
= null
Methods
__construct()
Initialize a duplicate constraint exception.
public
__construct([string|null $msg = null ][, int|null $code = null ][, Exception|null $parent = null ][, mixed $more = null ]) : mixed
Parameters
- $msg : string|null = null
-
Error message. Defaults to 'duplicate'.
- $code : int|null = null
-
HTTP status code. Defaults to 400.
- $parent : Exception|null = null
-
Previous exception for chaining.
- $more : mixed = null
-
Additional context data for debugging.
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
Return values
never —Always throws the constructed exception.