Runs a callable, catching any exception and reflecting it into a triggered error.
This allows you to combine exception generating code with retry code to trace the execution over the retry cycle. Example:
$retry = new \Haldayne\Fox\Retry(
$capture = new \Haldayne\Fox\CaptureErrors(
new \Haldayne\Fox\ExceptionToError(
function () { throw new \Exception('Oops!', rand(1,10)); }
)
)
);
$result = $retry();
if (false === $result) {
die(
$capture->
getCapturedErrors()->
pluck('message')->
into(new MapOfStrings)->
join(PHP_EOL)
);
}
package | Haldayne |
---|
__construct(callable $code)
callable
__invoke()
formatException(\Exception $ex)
getErrorCode()
getErrorMessageFormat()
setErrorCode($code)
setErrorMessageFormat($format)
The default format is: %1$s (%2$d) thrown at %3$s:%4$d as %5$s exception.
$code
null
$errorCode
E_USER_ERROR
$errorMessageFormat
'%1$s (%2$d) thrown at %3$s:%4$d as %5$s exception.'