Views: 5572 (Data available since 06.02.2017)
The new core uses the mechanism of exceptions.
Exception case (when an exception may be given) is an atypical situation when it makes no sense to continue the performance of the basic algorithm.
If a user has sent a form with an empty Name field, it is not an exception case. It is a regular expected case that must be handled appropriately.
But if in case of API method invocation in order to change an infoblock element an empty element id was specified, it is an exception case. It is unexpected and it makes no sense to continue changing the element.
If the method is waiting for the user id and you transmit a line, it is an exception, because the method does not know what to do with the line in this case.
If the GetList method accepts the timestamp filter, and developer has written “tymestamp,” it will be an exception.
There exists a notion of exception hierarchy. Its purpose is to handle exceptions, look up which of them tripped, and take the appropriate actions depending on it. The general hierarchy logic is as follows:
Bitrix\Main\SystemException - basic class of all system exceptions
Bitrix\Main\IO\IoException - basic class of all exceptions of file input-output
Bitrix\Main\IO\FileDeleteException - exception in case of file deletion
Bitrix\Main\IO\FileNotFoundException - absence of a required file
Bitrix\Main\IO\FileOpenException - exception in case of file opening
Bitrix\Main\IO\InvalidPathException - invalid path
Bitrix\Main\Config\ConfigurationException - configuration error
Bitrix\Main\Security\SecurityException - security error
Bitrix\Main\ArgumentException - basic class of exceptions associated with incoming parameters of methods
Bitrix\Main\ArgumentNullException - parameter must not be left empty
Bitrix\Main\ArgumentOutOfRangeException - parameter outside a permitted range
Bitrix\Main\ArgumentTypeException - inadmissible type parameter
Bitrix\Main\DB\DbException - basic class for database exceptions
Bitrix\Main\DB\ConnectionException - exception during connection
Bitrix\Main\DB\SqlException - exception during performance of a query
Bitrix\Main\NotSupportedException - is invoked if the functionality is not supported
Bitrix\Main\NotImplementedException - is invoked if the functionality must be supported but is not implemented so far
Bitrix\Main\LoaderException - exception in loader
Bitrix\Main\CustomException - basic type of all custom exceptions.
Exception sent must have the most appropriate type possible.