chroma-x/common-exceptions

A PHP library providing common exception classes used by different projects.

3.0.2 2021-01-18 12:59 UTC

This package is auto-updated.

Last update: 2024-12-18 21:39:25 UTC


README

SensioLabs Insight Code Climate Latest Stable Version Total Downloads License

A PHP library providing common exception classes used by different projects.

Installation

{
   	"require": {
        "chroma-x/common-exceptions": "~3.0"
    }
}

Usage

Autoloading and namesapce

require_once('path/to/vendor/autoload.php');

Handling exceptions

Catching by concrete class

try{
	// Perform something maybe throwing an exception
} catch (ChromaX\CommonException\NetworkException\ConnectionException $exception) {
	// API is not reachable
} catch (ChromaX\CommonException\NetworkException\CurlException $exception) {
	// Curl failed
} catch (ChromaX\CommonException\ApiException\InvalidResponseException $exception) {
	// API returns an unexpected result
} catch (ChromaX\CommonException\ApiException\RequestQuotaException $exception) {
	// API requests over the allowed limit
} catch (ChromaX\CommonException\ApiException\NoResultsException $exception) {
	// API request had no result
} catch (ChromaX\CommonException\IoException\FileWriteException $exception) {
	// Log file was not writable
}

Catching by parent class

try{
	// Perform something maybe throwing an exception
} catch (ChromaX\CommonException\NetworkException\Base\NetworkException $exception) {
	// Any network exception was thrown
} catch (ChromaX\CommonException\ApiException\Base\ApiException $exception) {
	// Any API exception was thrown
} catch (ChromaX\CommonException\IoException\Base\IoException $exception) {
	// Any IO exception was thrown
}

Catching by grand parent class

try{
	// Perform something maybe throwing an exception
} catch (ChromaX\CommonException\Base\BaseException $exception) {
	// Any exception was thrown
} 

Contribution

Contributing to our projects is always very appreciated.
But: please follow the contribution guidelines written down in the CONTRIBUTING.md document.

License

PHP Common Exceptions is under the MIT license.