Exception
Exception
Framework base exception with JSON serialization support.
class Exception extends \Exception implements \JsonSerializableExtends PHP's native exception to normalize default HTTP-style error codes, preserve context from chained exceptions, and expose a stable payload shape for API responses via JsonSerializable.
Properties
class
Class name captured from the previous exception, when available.
protected string $classtrace
Standard stack trace.
protected array $traceMethods
__construct
Constructs a new exception instance.
public __construct(string $message, int $code = 500, ?\Throwable $previousException): voidParameters
| Parameter | Type | Description |
|---|---|---|
$message | string | the Exception message to throw |
$code | int | the Exception code (defaults to 500 if not provided or if less than or equal to 0) |
$previousException | \Throwable | the previous throwable used for exception chaining |
jsonSerialize
Serializes the exception data to an array suitable for JSON encoding.
public jsonSerialize(): voidThe returned array always includes:
- 'timestamp': The current Unix timestamp with microseconds.
- 'code': The exception code.
- 'message': The exception message.
If the 'display_errors' INI setting is enabled, the array also includes:
- 'file': The filename where the exception was thrown.
- 'line': The line number where the exception was thrown.
- 'class': The class name of the exception.
- 'trace': The stack trace as an array.
getClass
public getClass(): stringgetStackTrace
Returns the stack trace as an array.
public getStackTrace(): voidIf a previous exception was provided during construction, its stack trace is returned. Otherwise, the standard stack trace of this exception is returned.
Generated by Hazaar API Doc Generator on Tue, 21 Apr 2026 04:00:23 +0000