A PHP library providing common exception classes used by different projects.
{
"require": {
"chroma-x/common-exceptions": "~3.0"
}
}
require_once('path/to/vendor/autoload.php');
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
}
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
}
try{
// Perform something maybe throwing an exception
} catch (ChromaX\CommonException\Base\BaseException $exception) {
// Any exception was thrown
}
Contributing to our projects is always very appreciated.
But: please follow the contribution guidelines written down in the CONTRIBUTING.md document.
PHP Common Exceptions is under the MIT license.