-
Notifications
You must be signed in to change notification settings - Fork 8
02 – Error Handling
Nicholas Jordon edited this page Aug 31, 2016
·
9 revisions
Error handling in PHP-Color has 3 modes:
- Exceptions
- Standard Errors
- Disabled
By default, all errors are reported via throwing exceptions.
NOTICE: All errors are recoverable. All errors will use some type default behavior, that will allow the application to continue running. (Given you properly catch exceptions)
Configuring:
\projectcleverweb\color\error::$active = TRUE;
\projectcleverweb\color\error::$use_exceptions = TRUE;
Example:
try {
// Unusable input (Exception Triggered)
$test = new color(new stdClass);
} catch (\projectcleverweb\color\exception $e) {
printf('Color Exeption: "%s"', $e);
}
// This will output '000000' because the default behavior for import errors sets the input to black.
echo $test->hex();
Configuring:
\projectcleverweb\color\error::$active = TRUE;
\projectcleverweb\color\error::$use_exceptions = FALSE;
Example:
// Warning: The color supplied to projectcleverweb\color\color's constructor was not valid in /example.php on line 2
$test = new color(new stdClass);
// Output: '000000'
echo $test->hex();
Configuring:
\projectcleverweb\color\error::$active = FALSE;
Example:
// No output or error of any kind, just silently sets the color to black.
$test = new color(new stdClass);
// Output: '000000'
echo $test->hex();
Copyright © 2016 Nicholas Jordon
This documentation is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License.