Skip to content

Commit

Permalink
add resolve handler
Browse files Browse the repository at this point in the history
  • Loading branch information
ArrayIterator committed Nov 10, 2023
1 parent 65f3067 commit 2286864
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/Utils/Caller.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace ArrayAccess\DnsRecord\Utils;

use function error_clear_last;
use Throwable;
use function restore_error_handler;
use function set_error_handler;

Expand All @@ -21,10 +21,14 @@ public static function track(
set_error_handler(static function ($code, $message) use (&$errorCode, &$errorMessage) {
$errorCode = $code;
$errorMessage = $message;
error_clear_last();
});
try {
return $callable(...$args);
} catch (Throwable $e) {
$errorCode = $e->getCode();
$errorMessage = $e->getMessage();
// error returning null
return null;
} finally {
restore_error_handler();
}
Expand All @@ -37,7 +41,7 @@ public static function call(
callable $callable,
...$args
) {
set_error_handler(static fn() => error_clear_last());
set_error_handler(static fn () => null);
try {
return $callable(...$args);
} finally {
Expand Down

0 comments on commit 2286864

Please sign in to comment.