PHP code example of cse / base-exceptions
1. Go to this page and download the library: Download cse/base-exceptions library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
cse / base-exceptions example snippets
try {
..
$code = 0;
} catch (CseExceptions $e) {
...
} catch (Throwable $e) {
$code = $e->getCode();
}
CseExceptions::getErrorMsg($code);
// Unknown error
class ModelExceptions extends CseExceptions
{
const ERROR_EXAMPLE_CODE_1 = 1;
const ERROR_EXAMPLE_CODE_2 = 2;
const ERROR_EXAMPLE_CODE_3 = 3;
/**
* @var array
*/
protected static $errorsMsg = [
self::ERROR_EXAMPLE_CODE_1 => 'Error code 1',
self::ERROR_EXAMPLE_CODE_2 => 'Error code 2',
self::ERROR_EXAMPLE_CODE_3 => 'Error code 3',
];
}
try {
...
throw new ModelExceptions('CseExceptions');
} catch (CseExceptions $e) {
$e->getMessage();
// CseExceptions
} catch (Exception $e) {
// Last Exception
} catch (Throwable $e) {
// Last Throwable
}
ModelExceptions::throwException(ModelExceptions::ERROR_EXAMPLE_CODE_1);
// Error code 1
ModelExceptions::throwException(ModelExceptions::ERROR_EXAMPLE_CODE_2, ' - msg test');
// Error code 2 - msg test
ModelExceptions::throwException(4);
// Unknown error
ModelExceptions::getErrorMsg(ModelExceptions::ERROR_EXAMPLE_CODE_3);
// Error code 3
ModelExceptions::getErrorMsg(4);
// Unknown error
bash
phpunit PATH/TO/PROJECT/tests/
bash
phpunit --configuration PATH/TO/PROJECT/phpunit.xml