error-handling
Skill4 starsChanged 4 months agoMITView on GitHub
Handle failures with exceptions in PHP 8.0+ — custom exception hierarchies, catching by type, try/finally cleanup, chaining, and the never return type. Use when the user must release a resource (file handle, lock, transaction) whether or not an exception is thrown on PHP 8.0+; the user needs domain-specific exceptions that callers can catch selectively on PHP 8.0+; the user wants to catch a low-level exception (PDO, cURL) and rethrow it as a domain exception without losing the cause on PHP 8.0+. Keywords: error-handling, exceptions, php80, never-type, try-finally.
80 other projects use a version of this.
Adopted by
Most recently taken up by
- codewithmukesh/dotnet-claude-kittheir own version, first seen Nov 8, 2026
- lhbsaa/apex-unifiedtheir own version, first seen Nov 8, 2026
- ahmadvahidi/skill-atlastheir own version, first seen Nov 8, 2026
- nisarth/claude-skills-storetheir own version, first seen Nov 8, 2026
- AndersonAndrad/skillstheir own version, first seen Nov 8, 2026
- Wade-DevCode/awesome-coding-skills-cntheir own version, first seen Nov 8, 2026
Used with
Projects with it also use convention-learner, caching and 9 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
codewithmukeshSkillconvention-learner
Detects and enforces project-specific coding conventions by analyzing existing codebase patterns. Learns naming conventions, folder structure, test organization, and coding style from the existing code. Load when: "conventions", "coding standards", "project patterns", "enforce style", "detect patterns", "learn conventions", "code consistency".
Also in 3 projects that use this
wpankSkillcaching
Caching strategies, invalidation, eviction policies, HTTP caching, distributed caching, and anti-patterns. Use when designing cache layers, choosing eviction policies, debugging stale data, or optimizing read-heavy workloads.
Also in 6 projects that use this
diego-tobalinaSkilllogging
Logging best practices for Java (SLF4J/Logback) and Node.js (Winston/Pino). Use for structured logging, log levels, and avoiding sensitive data exposure.
Also in 12 projects that use this
codewithmukeshSkillopentelemetry
OpenTelemetry observability for .NET 10 applications. Covers traces, metrics, and logs using the OpenTelemetry SDK with OTLP export. Includes custom ActivitySource, IMeterFactory metrics, resource configuration, and Aspire Dashboard integration. Load this skill when setting up distributed tracing, custom metrics, OTLP export, or when the user mentions "OpenTelemetry", "OTLP", "traces", "spans", "Activity", "ActivitySource", "metrics", "IMeterFactory", "Meter", "Counter", "Histogram", "Gauge", "telemetry", "observability", "distributed tracing", "OTEL", or "Aspire Dashboard".
Also in 3 projects that use this
MovGP0Skillmodern-csharp
Modern C# style guidance for Bendex and MicroSea code changes, including primary constructors, expression-bodied members, var usage, target-typed new, lambdas, and pattern matching.
Also in 3 projects that use this
MicrosoftSkillresilience
Apply resilience patterns (retry, backoff, circuit breaking) when writing or reviewing code that makes outbound HTTP/REST calls, database operations, or any I/O that can experience transient failures. Use this skill when: (1) writing new code that calls external services or APIs, (2) reviewing code that uses fetch, HTTP clients, or service-to-service calls, (3) adding queue consumers or workers that interact with remote systems, (4) debugging intermittent failures in production.
Also in 4 projects that use this
Other versions80 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 80
- microsoft/data-formulator★ 17ksame name
- epicenter-md/epicenter★ 4.8ksame name
- EpicenterHQ/epicenter★ 4.8ksame name
- software-mansion/react-native-executorch★ 1.8ksame name
- CloudAI-X/claude-workflow★ 1.4ksame name
- CloudAI-X/claude-workflow-v2★ 1.4ksame name
- codewithmukesh/dotnet-claude-kit★ 808same name
- alchemyplatform/aa-sdk★ 321same name
- Resgrid/Core★ 238same name
- DevelopersGlobal/ai-agent-skills★ 216same name
70 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository119 other files it gives its agents.
- strategy-bitrix-d7-incrementalSkill
- strategy-explicit-over-magicSkill
- strategy-framework-conventionsSkill
- strategy-legacy-safe-editsSkill
- strategy-minimal-diffSkill
- strategy-no-untested-refactorSkill
- strategy-preserve-public-apiSkill
- strategy-readonly-immutabilitySkill
- strategy-security-firstSkill
- strategy-test-drivenSkill
- openapiSkill
- paginationSkill
- rest-designSkill
- versioningSkill
- cqrsSkill
- dependency-inversionSkill
- hexagonalSkill
- repository-patternSkill
- service-layerSkill
- bitrixSkill
- findings-reportSkill
- laravelSkill
- performanceSkill
- phpSkill
- project-analysisSkill
- refactoringSkill
- roi-prioritizationSkill
- securitySkill
- stack-detectionSkill
- cache-layersSkill
- component-engineSkill
- d7-eventsSkill
- d7-loaderSkill
- d7-orm-queriesSkill
- iblock-elementsSkill
- kernel-main-moduleSkill
- localizationSkill
- controllersSkill
- ormSkill
- validationSkill
- controllersSkill
- query-builderSkill
- routingSkill
- autoload-psr4Skill
- dependency-managementSkill
- scriptsSkill
- connection-poolingSkill
- mysql-indexingSkill
- redisSkill
- transactionsSkill
- ci-github-actionsSkill
- deployment-strategiesSkill
- docker-phpSkill
- env-configSkill
- associationsSkill
- entities-mappingSkill
- orm-basicsSkill
- entity-apiSkill
- module-developmentSkill
- routing-controllersSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
3 rules. 0 are common, 1 is distinctive, and 2 are very specific to this project.
0
Common
Most of the 64 edited versions we read keep these.
1
Distinctive
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 64
Do not use this skill for ordinary control flow where a missing or absent value is an expected outcome, not a failure.
- Very specific: line 65
Do not use this skill when the intent is to suppress errors with @ or an empty catch to make a symptom disappear.
- Very specific: line 87
When rethrowing, pass the caught exception as the third $previous constructor argument (throw new OrderException('...', 0, $e);) rather …
“Common” is measured: kept by at least 6 in 10 of the 64 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
<!-- generated: do not edit — source: knowledge/atoms/php/error-handling/ --><!-- schema: atomVersion=3 skillVersion=2 graphVersion=1 --><!-- compile: @php-skills/compiler v1.0.0 (deterministic build) -->PHP Error Handling
When to use
- The user must release a resource (file handle, lock, transaction) whether or not an exception is thrown on PHP 8.0+.
- The user needs domain-specific exceptions that callers can catch selectively on PHP 8.0+.
- The user wants to catch a low-level exception (PDO, cURL) and rethrow it as a domain exception without losing the cause on PHP 8.0+.
When NOT to use
- Do not use this skill for ordinary control flow where a missing or absent value is an expected outcome, not a failure.
- Do not use this skill when the intent is to suppress errors with
@or an empty catch to make a symptom disappear.
Core guidance
- Catch the most specific exception type — Catch the narrowest exception type that you can actually handle
(
catch (PaymentDeclinedException $e)), not a blanketcatch (\Throwable $e). - Root the hierarchy in a marker base exception — Give each bounded context one base exception (
abstract class OrderException extends \RuntimeException) and extend it for specific failures. - Release resources in finally, not in each path — Put resource release (close handle, unlock, roll back) in a
finallyblock so it runs once on both the success and exception paths.
Quick recipe
- Declare one abstract or concrete base exception per bounded context extending an SPL
type (
class OrderException extends \RuntimeException). (verify: Callers cancatch (OrderException $e)for any order-domain failure) - Extend the base for each distinct failure and add static named constructors
(
PaymentDeclined::forOrder($id)) that build a rich message. (verify: Each failure type is catchable on its own and carries context in its message) - At integration boundaries, catch the low-level exception and rethrow the domain type
passing the original as
$previous; catch the domain base at the top-level handler. (verify: Logs show the domain exception with the original cause preserved via getPrevious())
Best practices
- When rethrowing, pass the caught exception as the third
$previousconstructor argument (throw new OrderException('...', 0, $e);) rather than discarding it - Give a function that always throws or exits the
neverreturn type (function fail(string $m): never) so callers and analyzers know it does not return
Anti-patterns
| Anti-pattern | Why it fails | Do instead |
| Catching Throwable everywhere | Blanket catches hide programming errors, defeat fail-fast behavior, and turn every bug into a swallowed no-op. | Catch specific, recoverable exception types locally and let one top-level handler<br>(framework exception handler) deal with the unexpected \Throwable. |
| Silencing with the @ operator | The @ operator suppresses the diagnostic but not the underlying problem, and it<br>disables logging so the failure vanishes. | Fix the condition that triggers the warning, guard with a check, or catch the<br>exception the operation throws; never mask it with @. |
| Using exceptions for normal control flow | Exceptions are costly and obscure intent when used for expected branches; they should signal genuinely exceptional states. | Return a nullable value, an Option/Result type, or a boolean for expected outcomes and reserve exceptions for real failures. |
See references/anti-patterns.md.
Common mistakes
- catch(Exception) misses Error types —
catch (\Exception $e)does not catch\Errorsubtypes (TypeError,UnhandledMatchError), because both extend\Throwable, not\Exception. Fix: Catch\Throwableat a top-level boundary when you genuinely must handle both exceptions and errors; otherwise catch the specific exception types you can recover from. - Rethrowing without the previous exception — Catching a low-level error and throwing a new one without passing
$previousdrops the original stack trace and root cause. Fix: Always pass the caught exception as the third constructor argument (throw new DomainException('...', 0, $e);) sogetPrevious()retains the cause. - Empty catch block silently swallows failures — A
catch (\Throwable $e) {}with an empty body discards the error and lets execution continue as if nothing failed. Fix: Handle, log, or rethrow the exception; if catching truly is intentional (e.g. optional cache warm-up), log at minimum and document why it is safe to ignore.
Version notes
- never return type added in PHP 8.1 (PHP >=8.1) — The
neverreturn type, for functions that always throw or exit, is available from PHP 8.1; on 8.0 and earlier express the intent only with a@return neverdocblock.
Security
- Do not leak exception details to clients — Never render raw exception messages, stack traces, SQL, or file paths to end users; log the full detail server-side and return a generic message with a correlation id.
Testing
- Activation and decision behavior are verified in
eval/scenarios/php/error-handling.yaml.
Additional resources
- references/anti-patterns.md
- references/core.md
- references/examples.md
- references/pitfalls.md
- references/recipes.md
- references/version-differences.md
Knowledge graph
Related: php/enums, php/match-expression
<!-- graph-fragment: graph/fragments/php/error-handling.yaml -->Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

