It is assumed
- All exceptions are derived from the same root.
- All exceptions are divided into Logic and Runtime.
Thus it is possible to catch
- All exceptions that were thrown specific library
- All Runtime (for example) exceptions, regardless of where they thrown
In axy\errors defined following basic exception:
Error(interface)Logic(class extends fromErrorand globalLogicException)Runtime(class extends fromErrorand globalRuntimeException)
In additional, in the library defined some number more specific basic classes (ItemNotFound for example).
List is given in the relevant part.
We propose the following scheme.
For example, there is a library in my\ns namespace.
All exception classes of this library are located in my\ns\errors.
Define the interface my\ns\errors\Error (implements axy\errors\Error).
This is basic exception of the library.
All concrete classes are inherit from Error and from axy\error\Logic or axy\error\Runtime (or more specific class).
namespace my\ns\errors;
class InvalidMyConfig extends \axy\errors\InvalidConfig implements Error
{
}In this way InvalidMyConfig is successor of follow classes
ExceptionLogicException- catch all Logic-errors.axy\errors\Erroraxy\errors\Logicaxy\error\InvalidConfig- catch all invalid configs.my\ns\errors\Error- catch allmy\nslibrary errors.
The constructor of basic Logic and Runtime has the following form
__constructor([mixed $message [, int $code [, Exception $previous [, mixed $thrower])It has the following differences from the standard constructor
$messagemay be not only a string. It may be an array for message template.$throweris pointer of who threw an exception. See trace truncate.
The constructors of the other classes can take more specific arguments instead $message and $code.
But all axy\errors classes take $previous and $thrower as latest arguments.
For example: FieldNotExists::__constructor([$key [, $container [, $previous [, $thrower]).
Here $key is the key which was not found in $container.