Standard Exceptions 2

Exceptions

Not a sexy topic

Let's face it!

throw new \exception

Does NOT

or

catch(\exception)

Why do i see this in PHPStorm?

If we hate exceptions

SO MUCH

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!

Goals

  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
Email: thecrazycodr@gmail.com

Open source contributions

Contact me

Made with Slides.com