Skip to content

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

License

Notifications You must be signed in to change notification settings

chroma-x/php-common-exceptions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP Common Exceptions

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.