} catch (CodeException $e) {
throw new BusinessException([]);
}
This allow to have the original CodeException message but not it's stacktrace , so information are loose
instead, PHP already have a builtin mechanism for that , which is the previous: Exception $e parameter in Exception constructors which allow to do the following construction (adminting you don't override the constructor
} catch (CodeException $e) {
throw new BusinessException('my business message', previous: $e );
}
This allow to
keep both the business and code stacktrace
allow you to not have to reconstruct a "original message : %s"
(One short paragraph is enough)
Example of how to use this feature(Show some PHP code and/or YAML config explaining how to use this feature in a real app)
transform
final class EntityRemoveException extends BaseException
{
public function __construct(array $parameters = [])
{
$exceptionContext = new ExceptionContext(
'exception.entity_remove',
sprintf('There is a ForeignKeyConstraintViolationException for the Doctrine entity associated with "%s". Solution: disable the "delete" action for this CRUD controller or configure the "cascade={"remove"}" attribute for the related field in the Doctrine entity. Full exception: %s', $parameters['entity_name'], $parameters['message']),
$parameters,
409
);
parent::__construct($exceptionContext);
}
}
into
final class EntityRemoveException extends BaseException
{
public function __construct(string $entityName, Exception $previous)
{
$exceptionContext = new ExceptionContext(
'exception.entity_remove',
sprintf('There is a ForeignKeyConstraintViolationException for the Doctrine entity associated with "%s". Solution: disable the "delete" action for this CRUD controller or configure the "cascade={"remove"}" attribute for the related field in the Doctrine entity.', $parameters['entity_name']),
$parameters,
409
);
parent::__construct($exceptionContext, previous $previous);
}
}
Short description of what this feature will allow to do:
It will allow to have a more precise context of the original exception
Currently for
EntityRemoveException
(and certainly other exception in easyadmin bundle) the usage is the followingi.e
This allow to have the original CodeException message but not it's stacktrace , so information are loose
instead, PHP already have a builtin mechanism for that , which is the
previous: Exception $e
parameter in Exception constructors which allow to do the following construction (adminting you don't override the constructorThis allow to
(One short paragraph is enough)
Example of how to use this feature (Show some PHP code and/or YAML config explaining how to use this feature in a real app)
transform
into
so that you could then do