Skip to content

02 – Error Handling

Nicholas Jordon edited this page Aug 30, 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)

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();

Standard Errors

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();

Disabling Errors

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();


Previous Page - Getting Started     Next Page