Standard Exceptions 2.0.0

by thecrazycodr

What is it?

  • Library of pre-made exceptions
  • Namespaced for convenience
  • Very flexible through the use of tagging interfaces

A few exceptions

http://www.wordclouds.com/

A few exceptions (part 1)

EmptyException
FullException
KeyAlreadyExistsException
KeyNotFoundException
ReadOnlyArrayException
ReadOnlyArrayItemException
FormatException
IntegrityException
NotFoundException
TypeException

ValidationException
BadRequestException
ConflictException
ForbiddenException
MethodNotAllowedException
NotAcceptableException
NotFoundException
RequestedRangeNotSatisfiableException
RequestEntityTooLargeException
UnauthorizedException

A few exceptions (part 2)

UnprocessableEntityException
UnsupportedMediaTypeException
InternalServerErrorException
NotImplementedException
ServiceUnavailableException
DirectoryNotFoundException
DirectoryNotReadableException
DirectoryNotWritableException
FileNotFoundException
FileNotReadableException

FileNotWritableException
NotADirectoryException
NotAFileException
ConnectionLostException
ConnectionRefusedException
UnexpectedResponseException
UnknownHostException
InvalidOperationException
NotImplementedException
UnexpectedException
InvalidDataException
NotFoundException

Conveniently namespaced

  • Collection
  • Data
  • Http
    • ClientError
    • ServerError
  • IO
    • Filesystem
    • Network
  • Operation
  • Tag

Tagging interfaces

Library provides interfaces that tag and convey similar meaning through many different exceptions.

 

They allow you as a dev to catch a meaning instead of a context.

try {
    $storage->getProducts();
}catch(FileNotFoundException $ex){
    //The file for $storage 
    //engine cannot be found
}
try {
    $storage->getProducts();
}catch(DataNotFoundException $ex){
    //The data for $storage 
    //engine cannot be found
}

Or

Advantages

  • Less painful exception writing
  • Less painful \exception usage
  • Better flexibility and interop

Disadvantages

  • Less precise contexts
  • Still in the PHP user-land

Installing

composer require crazycodr/standard-exceptions

Usage

class HomeController {

    public function index(){
        throw new Exceptions\Operation\NotImplementedException();
    }

}

thecrazycodr@gmail.com

Standard Exceptions 2.0.0

By Mathieu Dumoulin

Standard Exceptions 2.0.0

Presentation of my open-source exceptions project!

  • 582
Loading comments...

More from Mathieu Dumoulin