# ExceptionSnapshot

> Represents a captured throwable without executable state.

[API reference](/docs/api/index.md) › [Debug Core](/docs/extensions/debug-core/reference/index.md) › [Storage](/docs/extensions/debug-core/reference/storage/index.md) › ExceptionSnapshot

| final readonly class | `PHPForge\Debug\Storage\ExceptionSnapshot` |
| --- | --- |
| Implements | [`JsonSerializable`](https://www.php.net/manual/en/class.jsonserializable.php), [`Stringable`](https://www.php.net/manual/en/class.stringable.php) |
| Source | [`src/Storage/ExceptionSnapshot.php`](https://github.com/php-forge/debug-core/blob/main/src/Storage/ExceptionSnapshot.php#L22) |

Represents a captured throwable without executable state.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`__construct()`](#method-__construct) | Frame arguments stay in their tagged form so a snapshot read back from disk re-serializes byte for byte; newly captured snapshots deliberately persist an empty argument list. | `ExceptionSnapshot` |
| [`__toString()`](#method-__toString) | Returns the original throwable text captured in the snapshot. | `ExceptionSnapshot` |
| [`fromArray()`](#method-fromArray) static | Hydrates a throwable snapshot from decoded JSON data. | `ExceptionSnapshot` |
| [`fromThrowable()`](#method-fromThrowable) static | Captures a throwable and its previous-exception chain without executable state. | `ExceptionSnapshot` |
| [`getClass()`](#method-getClass) | Returns the captured throwable class. | `ExceptionSnapshot` |
| [`getCode()`](#method-getCode) | Returns the captured throwable code. | `ExceptionSnapshot` |
| [`getFile()`](#method-getFile) | Returns the file where the throwable originated. | `ExceptionSnapshot` |
| [`getLine()`](#method-getLine) | Returns the line where the throwable originated. | `ExceptionSnapshot` |
| [`getMessage()`](#method-getMessage) | Returns the captured throwable message. | `ExceptionSnapshot` |
| [`getPrevious()`](#method-getPrevious) | Returns the previous throwable snapshot or `null`. | `ExceptionSnapshot` |
| [`getTrace()`](#method-getTrace) | Returns the trace frames with their arguments projected to plain display values. | `ExceptionSnapshot` |
| [`jsonSerialize()`](#method-jsonSerialize) | Returns the throwable snapshot for JSON serialization. | `ExceptionSnapshot` |

## Method details

### __construct() <span id="method-__construct"></span>

```php
public function __construct(string $class, string $message, int|string $code, string $file, int $line, list<array{namespace: string, short_class: string, class: string, type: string, function: string|null, file: string|null, line: int|null, args: PHPForge\Debug\Storage\DebugArray}> $trace, string $toString, self|null $previous)
```

Frame arguments stay in their tagged form so a snapshot read back from disk re-serializes byte for byte; newly
captured snapshots deliberately persist an empty argument list.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$class` | `string` | Captured throwable class. |
| `$message` | `string` | Captured throwable message. |
| `$code` | `int\|string` | Captured throwable code. |
| `$file` | `string` | File where the throwable originated. |
| `$line` | `int` | Line where the throwable originated. |
| `$trace` | `list<array{namespace: string, short_class: string, class: string, type: string, function: string\|null, file: string\|null, line: int\|null, args:` [`DebugArray`](/docs/extensions/debug-core/reference/storage/debugarray/index.md)`}>` | Captured trace frames. |
| `$toString` | `string` | Original throwable text. |
| `$previous` | `self\|null` | Previous throwable snapshot or `null`. |

### __toString() <span id="method-__toString"></span>

```php
public function __toString(): string
```

Returns the original throwable text captured in the snapshot.

**Returns**

`string`: Original throwable text.

### fromArray() <span id="method-fromArray"></span>

```php
public static function fromArray(mixed $data, string $path = '$.exception'): self
```

Hydrates a throwable snapshot from decoded JSON data.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$data` | `mixed` | Decoded throwable payload. |
| `$path` | `string` | Payload path used in hydration errors. |

**Returns**

`self`: Hydrated throwable snapshot.

### fromThrowable() <span id="method-fromThrowable"></span>

```php
public static function fromThrowable(Throwable $throwable): self
```

Captures a throwable and its previous-exception chain without executable state.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$throwable` | [`Throwable`](https://www.php.net/manual/en/class.throwable.php) | Throwable to capture. |

**Returns**

`self`: Captured throwable snapshot.

### getClass() <span id="method-getClass"></span>

```php
public function getClass(): string
```

Returns the captured throwable class.

**Returns**

`string`: Captured throwable class.

### getCode() <span id="method-getCode"></span>

```php
public function getCode(): int|string
```

Returns the captured throwable code.

**Returns**

`int|string`: Captured throwable code.

### getFile() <span id="method-getFile"></span>

```php
public function getFile(): string
```

Returns the file where the throwable originated.

**Returns**

`string`: Origin file path.

### getLine() <span id="method-getLine"></span>

```php
public function getLine(): int
```

Returns the line where the throwable originated.

**Returns**

`int`: Origin line number.

### getMessage() <span id="method-getMessage"></span>

```php
public function getMessage(): string
```

Returns the captured throwable message.

**Returns**

`string`: Captured throwable message.

### getPrevious() <span id="method-getPrevious"></span>

```php
public function getPrevious(): self|null
```

Returns the previous throwable snapshot or `null`.

**Returns**

`self|null`: Previous throwable snapshot or `null`.

### getTrace() <span id="method-getTrace"></span>

```php
public function getTrace(): list<array<string, mixed>>
```

Returns the trace frames with their arguments projected to plain display values.

**Returns**

`list<array<string, mixed>>`: Display-safe trace frames.

### jsonSerialize() <span id="method-jsonSerialize"></span>

```php
public function jsonSerialize(): array<string, mixed>
```

Returns the throwable snapshot for JSON serialization.

**Returns**

`array<string, mixed>`: Serialized throwable snapshot.