Leveraging Typed Exceptions for Cleaner Error Handling
summary
Argues that typed exceptions simplify layered PHP code by replacing sentinel returns with real error types, showing Doctrine’s getSingleResult throwing NoResultException or NonUniqueResultException and the creation of a UserWasNotFound exception that bubbles up or is caught and translated, simplifying a product service and controller. Demonstrates PHPUnit’s expectException for tests, uses ben ramsey UUIDs to generate bogus IDs, and recommends catching ORM exceptions, embedding helpful messages, and preferring many specific exception classes over numeric status codes.
AI-written summary · about
chapters (15)
- 0:00Start
- 4:27Validation Methods
- 7:53Layered Architectures
- 9:51Error Signaling
- 11:38Layered Architecture with Exceptions
- 13:41Failure Modes
- 13:51The User Could Not Be Found
- 20:50Inconsistent Return Types
- 28:23The Exception Flow
- 30:46Better Practices for Exceptions
- 31:37Custom Exception Classes
- 33:17Catching Polymorphic Exceptions
- 38:49Pipes
- 40:37Live Coding
- 46:06Takeaways
related talks
38mLeveraging Typed Exceptions for Cleaner Error Handling
42mLeveraging Typed Exceptions for Cleaner Error Handling
35mHandling Exceptional Conditions with Grace and Elegance
31mException design - the art of making debugging more accurate
51mPHP ❤️ types
51mExceptions in PHP: more complicated than it appears
30mThe World of Laravel Exceptions
44mModern PHP Standards and Community
