diff --git a/src/Utils/Caller.php b/src/Utils/Caller.php index 19e1b52..2665fb7 100644 --- a/src/Utils/Caller.php +++ b/src/Utils/Caller.php @@ -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; @@ -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(); } @@ -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 {