chroma-x / common-exceptions
A PHP library providing common exception classes used by different projects.
Installs: 20 196
Dependents: 8
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 1
Open Issues: 0
pkg:composer/chroma-x/common-exceptions
Requires
- php: >=5.3
 
README
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.