Exception

Class System\Exception is a direct descendant of \Exception, in the constructor it receives not only a string, but also an array of strings. This allows you to group exceptions:

$errors = [];
if (empty($user['LOGIN'])) $errors[] = "Specify login";
if (empty($user['EMAIL'])) $errors[] = "Specify email";
if (empty($user['PASSWORD'])) $errors[] = "Specify password";
if ($errors) throw new \System\Exception($errors);

Further this exception can be caught and processed as \Exception, in this case the method getMessage() glues the array into a string. It is recommended to catch exceptions as \System\Exception and use the method getArray() to access the array of exception strings.

try {
	// call with possibility of exception
} catch (\System\Exception $Exception) {
	$errors = $Exception->getArray();
	\System\Engine::I()->ShowErrors($errors);
} catch (\Exception $Exception) {
	$error = $Exception->getMessage();
	\System\Engine::I()->ShowErrors([$error]);
}

Descendant classes

The descendant classes listed below do not have any additional internal functionality. Some of them are processed in a special way by the Engine.

Own exception

In order to use this exception in your module, you have a choice:

namespace Example;
class Exception extends \System\Exception {}
Ask question