# Laravel:exception Handling And Logging

> Use reportable/renderable exceptions, structured logs, and channel strategy for observability and graceful failures

- Skill: `jpcaparas/laravel-exception-handling-and-logging` (Agent Skill)
- Install (CLI): `npx skillmds@latest add jpcaparas/laravel-exception-handling-and-logging`
- Raw SKILL.md: https://api.skillmd.com/api/skills/jpcaparas/laravel-exception-handling-and-logging/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: jpcaparas (https://skillmd.com/u/jpcaparas)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/jpcaparas/laravel-exception-handling-and-logging

---


# Exception Handling and Logging

Treat errors as first-class signals; provide context and paths to remediation.

## Commands

```
// app/Exceptions/Handler.php
public function register(): void
{
    $this->reportable(function (DomainException $e) {
        Log::warning('domain exception', ['code' => $e->getCode()]);
    });

    $this->renderable(function (ModelNotFoundException $e, $request) {
        if ($request->expectsJson()) {
            return response()->json(['message' => 'Not Found'], 404);
        }
    });
}
```

## Patterns

- Use domain-specific exceptions for expected error paths
- Add structured context to logs; avoid logging secrets
- Route noisy logs to separate channels; keep defaults actionable
- Convert to API-appropriate responses in `renderable()`


