Exception
Exception
Framework base exception with JSON serialization support.
class Exception extends \Exception implements \JsonSerializableExtends: Exception
Implements: JsonSerializable
Extends 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 $classType: string
trace
Standard stack trace.
protected array $traceType: array
Methods
__construct
Constructs a new exception instance.
public __construct(string $message, int $code = 500, ?\Throwable $previousException): voidThe exception code doubles as the HTTP response status throughout the framework (see Hazaar\Controller\Error::setException), so it's constrained to the valid HTTP status range (100-599). Codes outside that range — e.g. a PDO SQLSTATE or driver error code passed through from a wrapped exception — are not valid HTTP statuses and would otherwise reach the response writer unchanged, which some SAPIs (e.g. FrankenPHP) treat as fatal rather than rejecting gracefully. Such codes are normalized to 500 and appended to the message so the original value isn't lost.
Parameters
| Parameter | Type | Description |
|---|---|---|
$message | string | the Exception message to throw |
$code | int | the Exception code (defaults to 500 if not provided or outside the 100-599 HTTP status range) |
$previousException | Throwable | the previous throwable used for exception chaining |
jsonSerialize
Serializes the exception data to an array suitable for JSON encoding.
public jsonSerialize(): arrayReturns: array
The 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(): stringReturns: string
getStackTrace
Returns the stack trace as an array.
public getStackTrace(): arrayReturns: array
If 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 Fri, 04 Sep 2026 23:32:16 +0000