<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/php-errors-exceptions-and-result-types-designing-failure-boundaries-vvlgsngnx" -->

---
title: PHP Errors, Exceptions, and Result Types: Designing...
description: A deep dive into designing failure boundaries in PHP through a partner-payment workflow, distinguishing invalid input, business declines, transient provider...
canonical: https://daily.dev/posts/php-errors-exceptions-and-result-types-designing-failure-boundaries-vvlgsngnx
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: PHP Errors, Exceptions, and Result Types: Designing Failure Boundaries | daily.dev
og:description: A deep dive into designing failure boundaries in PHP through a partner-payment workflow, distinguishing invalid input, business declines, transient provider...
og:url: https://daily.dev/posts/php-errors-exceptions-and-result-types-designing-failure-boundaries-vvlgsngnx
og:image: https://api.daily.dev/og/posts/VVlgsngnx.png
og:image:alt: PHP Errors, Exceptions, and Result Types: Designing Failure Boundaries
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# PHP Errors, Exceptions, and Result Types: Designing Failure Boundaries

**[W endell Adriel](https://daily.dev/sources/wendelladriel)** · [@wendell_adriel](https://daily.dev/wendell_adriel) · 20 min read · 15 upvotes · 2 comments

## Summary

A deep dive into designing failure boundaries in PHP through a partner-payment workflow, distinguishing invalid input, business declines, transient provider failures, and programming defects. Covers using result types (like PaymentOutcome) for normal business alternatives, translating provider exceptions at adapter boundaries while preserving the original throwable, implementing idempotency-safe retries with bounded backoff, presenting failures appropriately at HTTP/CLI boundaries, testing failure contracts with Pest, and logging observability data without leaking secrets. Concludes with a practical operational checklist for shipping payment integrations safely.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://wendelladriel.com/blog/php-errors-exceptions-and-result-types-designing-failure-boundaries>

## Questions this post answers

### How should I represent a declined payment differently from a provider timeout in PHP?

A declined payment is a normal business outcome and should be returned as an explicit result type, such as a PaymentDeclined value object with a reason, while a provider timeout is a transient transport failure and should be represented with a retryable exception like PaymentProviderUnavailable. This distinction matters because a decline is a final answer, but a timeout only means no response was received, so retrying it blindly could double-charge a customer.

_daily.dev surfaces practical patterns like this for developers building safer payment integrations in PHP._

### Why shouldn't I catch Throwable in PHP application code?

Catching Throwable mixes Exception, which represents interrupted business operations, with Error, which represents programming defects like TypeError or calling an undefined method. Catching Throwable around a payment attempt and returning false makes a TypeError look identical to a legitimate business failure, hiding real bugs. Throwable should only be caught at a true process boundary, such as a command runner or set_exception_handler, not inside domain or application code.

_developers refining PHP error-handling strategy can track patterns like this on daily.dev._

### How do I make payment retries safe without double-charging a customer after a timeout?

Use an idempotency contract: create a durable payment-attempt record with a stable ID before calling the provider, and pass that same ID as the provider's idempotency key on every retry. If a timeout occurs, reconcile the ambiguous attempt using the provider's lookup endpoint for that key instead of issuing a new capture request, since a timeout only means no response was received, not that the charge failed.

_daily.dev helps developers stay sharp on idempotency and retry patterns for payment systems._

## Community discussion

Top comments from developers on daily.dev.

**@pdfopsdev** · 0 upvotes

> the idempotency key point is the whole ballgame honestly, half the "duplicate charge" bugs I've debugged were retries without one. strong agree on Result types for business declines too, exceptions for that always end up with some catch(Throwable) swallowing a real bug six months later.

**@agustinbarrientos** · 0 upvotes

> Can a fake provider reproduce an ambiguous timeout caused by a response lost after capture? A repeated success seems easy to fake. The uncertain state is the interesting part.

## Similar posts on daily.dev

- [System Design Drill Day 10: Circuit Breakers, Timeouts and Degradation](https://daily.dev/posts/system-design-drill-day-10-circuit-breakers-timeouts-and-degradation-dw1gagwlk) · C\# Corner · 0 upvotes · 0 comments
- [When Retries Make Things Worse: Protecting Your System From Overload](https://daily.dev/posts/when-retries-make-things-worse-protecting-your-system-from-overload-gersnb7xl) · W endell Adriel · 2 upvotes · 0 comments
- [The two kinds of error](https://daily.dev/posts/the-two-kinds-of-error-zsfcltzzr) · Lobsters · 0 upvotes · 0 comments
- [Backend Challenges Teams Face When Processing Repeat Payments](https://daily.dev/posts/backend-challenges-teams-face-when-processing-repeat-payments-ps62emvxr) · freeCodeCamp · 1 upvotes · 0 comments

---

Tags: [#testing](https://daily.dev/tags/testing), [#architecture](https://daily.dev/tags/architecture), [#php](https://daily.dev/tags/php)

[View this post on daily.dev](https://daily.dev/posts/php-errors-exceptions-and-result-types-designing-failure-boundaries-vvlgsngnx)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"PHP Errors, Exceptions, and Result Types: Designing Failure Boundaries","url":"https://daily.dev/posts/php-errors-exceptions-and-result-types-designing-failure-boundaries-vvlgsngnx","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/php-errors-exceptions-and-result-types-designing-failure-boundaries-vvlgsngnx"},"datePublished":"2026-08-27T10:40:40.367Z","dateModified":"2026-09-14T10:00:18.396Z","description":"A deep dive into designing failure boundaries in PHP through a partner-payment workflow, distinguishing invalid input, business declines, transient provider...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/54a91efbf9538593bbdb47446048eb7a?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/54a91efbf9538593bbdb47446048eb7a?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"W endell Adriel","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Person","name":"Wendell Adriel","url":"https://daily.dev/wendell_adriel","image":"https://avatars1.githubusercontent.com/u/11641518?v=4","interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"EndorseAction"},"userInteractionCount":800}},"commentCount":2,"discussionUrl":"https://daily.dev/posts/php-errors-exceptions-and-result-types-designing-failure-boundaries-vvlgsngnx","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":15},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":2}],"keywords":"testing,architecture,php","timeRequired":"PT20M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"W endell Adriel","item":"https://daily.dev/sources/wendelladriel"},{"@type":"ListItem","position":3,"name":"PHP Errors, Exceptions, and Result Types: Designing Failure Boundaries"}]}
{"@context":"https://schema.org","@type":"WebPage","@id":"https://daily.dev/posts/php-errors-exceptions-and-result-types-designing-failure-boundaries-vvlgsngnx","comment":[{"@type":"Comment","text":"the idempotency key point is the whole ballgame honestly, half the “duplicate charge” bugs I’ve debugged were retries without one. strong agree on Result types for business declines too, exceptions for that always end up with some catch(Throwable) swallowing a real bug six months later.","datePublished":"2026-08-27T18:09:07.965Z","url":"https://daily.dev/posts/VVlgsngnx#c-pyOxCw4Jr","author":{"@type":"Person","name":"PDFops","url":"https://daily.dev/pdfopsdev","image":"https://media.daily.dev/image/upload/s---8isRBKc--/f_auto/v1782922291/avatars/avatar_orjMeK8QKaaVZwGq7ScPz?_a=BAMAMicg0"}},{"@type":"Comment","text":"Can a fake provider reproduce an ambiguous timeout caused by a response lost after capture? A repeated success seems easy to fake. The uncertain state is the interesting part.","datePublished":"2026-08-30T13:44:07.169Z","url":"https://daily.dev/posts/VVlgsngnx#c-GMdWY1cNK","author":{"@type":"Person","name":"Agustin Barrientos","url":"https://daily.dev/agustinbarrientos","image":"https://media.daily.dev/image/upload/s--5ayxQnqn--/f_auto/v1788281802/avatars/avatar_wQYYVe5Tbj0NJ7C7qPoa8?_a=BAMAMicg0"}}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/php-errors-exceptions-and-result-types-designing-failure-boundaries-vvlgsngnx#faq","mainEntity":[{"@type":"Question","name":"How should I represent a declined payment differently from a provider timeout in PHP?","acceptedAnswer":{"@type":"Answer","text":"A declined payment is a normal business outcome and should be returned as an explicit result type, such as a PaymentDeclined value object with a reason, while a provider timeout is a transient transport failure and should be represented with a retryable exception like PaymentProviderUnavailable. This distinction matters because a decline is a final answer, but a timeout only means no response was received, so retrying it blindly could double-charge a customer. daily.dev surfaces practical patterns like this for developers building safer payment integrations in PHP."}},{"@type":"Question","name":"Why shouldn't I catch Throwable in PHP application code?","acceptedAnswer":{"@type":"Answer","text":"Catching Throwable mixes Exception, which represents interrupted business operations, with Error, which represents programming defects like TypeError or calling an undefined method. Catching Throwable around a payment attempt and returning false makes a TypeError look identical to a legitimate business failure, hiding real bugs. Throwable should only be caught at a true process boundary, such as a command runner or set_exception_handler, not inside domain or application code. developers refining PHP error-handling strategy can track patterns like this on daily.dev."}},{"@type":"Question","name":"How do I make payment retries safe without double-charging a customer after a timeout?","acceptedAnswer":{"@type":"Answer","text":"Use an idempotency contract: create a durable payment-attempt record with a stable ID before calling the provider, and pass that same ID as the provider's idempotency key on every retry. If a timeout occurs, reconcile the ambiguous attempt using the provider's lookup endpoint for that key instead of issuing a new capture request, since a timeout only means no response was received, not that the charge failed. daily.dev helps developers stay sharp on idempotency and retry patterns for payment systems."}}]}
```

