Standard Exceptions 2


Not a sexy topic

Let's face it!

throw new \exception

Does NOT



Why do i see this in PHPStorm?

If we hate exceptions


I counted them, there are

11 different InvalidArgumentException

in my small project... WTF?

  • FileNotFoundException
  • NotImplementedException
  • DataNotFoundException

And many more...

These are all common exceptions repeated over and over and over again...

Breaks interop between libraries

How can you catch the right exception if we have 11 copies of the same exception through different libraries!

Why rewrite so much

If we hate creating exceptions so much, why do we reproduce and recreate them so much?

Standard Exceptions

  • Is a collection of generic but overly repeated exceptions.
  • They also are better organized in namespaces!


  1. Provide varied generic exceptions so people stop throwing and catching \Exception
  2. Encourage libraries to be interroperable by reusing the same exceptions everywhere instead of redefining them
  3. Convey means instead of context through tag interfaces

Example Exceptions

  • \Exceptions\Data\NotFoundException
  • \Exceptions\Operations\InvalidOperationException
  • \Exceptions\IO\FileSystem\FileNotFoundException
  • And many more (40 more actually)

Using Standard-Exceptions

composer require crazycodr/standard-exceptions

Check it out!

And contribute if you have ideas!

Mathieu Dumoulin

Senior Dev @ Learning Bird

Twitter: @thecrazycodr
LinkedIn: @crazycoders
GitHub: @crazycodr

Open source contributions

Contact me

Standard Exceptions - Lightning Talk - Confoo 2017

By Mathieu Dumoulin

Standard Exceptions - Lightning Talk - Confoo 2017

Lightning Talk about my exceptions library called Standard-Exceptions presented at #confoo 2017 in #montreal

  • 545