Documentation

LwtException extends RuntimeException

Base exception class for all LWT-specific exceptions.

Provides common functionality for exception handling including:

  • Structured context data for logging
  • HTTP status code mapping
  • User-friendly message generation
Tags
since
3.0.0

Table of Contents

Properties

$context  : array<string, mixed>
Additional context data for logging/debugging.
$httpStatusCode  : int
HTTP status code to return (for web responses).
$shouldLog  : bool
Whether this exception should be logged.

Methods

__construct()  : mixed
Create a new LWT exception.
getContext()  : array<string, mixed>
Get the context data for this exception.
getHttpStatusCode()  : int
Get the HTTP status code for this exception.
getUserMessage()  : string
Get a user-friendly message for display.
setHttpStatusCode()  : self
Set the HTTP status code.
shouldLog()  : bool
Whether this exception should be logged.
toArray()  : array<string, mixed>
Convert exception to array for logging/JSON responses.
withContext()  : self
Add context data to the exception.

Properties

$context

Additional context data for logging/debugging.

protected array<string, mixed> $context = []

$httpStatusCode

HTTP status code to return (for web responses).

protected int $httpStatusCode = 500

$shouldLog

Whether this exception should be logged.

protected bool $shouldLog = true

Methods

__construct()

Create a new LWT exception.

public __construct([string $message = '' ][, int $code = 0 ][, Throwable|null $previous = null ][, array<string, mixed> $context = [] ]) : mixed
Parameters
$message : string = ''

The exception message

$code : int = 0

The exception code (default: 0)

$previous : Throwable|null = null

The previous exception for chaining

$context : array<string, mixed> = []

Additional context data

getContext()

Get the context data for this exception.

public getContext() : array<string, mixed>
Return values
array<string, mixed>

getHttpStatusCode()

Get the HTTP status code for this exception.

public getHttpStatusCode() : int
Return values
int

getUserMessage()

Get a user-friendly message for display.

public getUserMessage() : string

Override in subclasses to provide sanitized messages safe for users.

Return values
string

setHttpStatusCode()

Set the HTTP status code.

public setHttpStatusCode(int $code) : self
Parameters
$code : int

HTTP status code

Return values
self

shouldLog()

Whether this exception should be logged.

public shouldLog() : bool
Return values
bool

toArray()

Convert exception to array for logging/JSON responses.

public toArray([bool $includeTrace = false ]) : array<string, mixed>
Parameters
$includeTrace : bool = false

Whether to include stack trace

Return values
array<string, mixed>

withContext()

Add context data to the exception.

public withContext(string $key, mixed $value) : self
Parameters
$key : string

Context key

$value : mixed

Context value

Return values
self

        
On this page

Search results