Skip to content

Commit e5e81a6

Browse files
committed
minor #43778 Use try/finally to restore error handlers (derrabus)
This PR was merged into the 5.4 branch. Discussion ---------- Use try/finally to restore error handlers | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | N/A | License | MIT | Doc PR | N/A This PR attempts to make some code dealing with temporary error handlers a bit more robust by making sure the old error handler is always restored. A forgotten error handler is pretty hard to debug, so I'd like our code to be a it more defensive here. Commits ------- 057716c6a2 Use try/finally to restore error handlers
2 parents ab95d4e + 5685f0c commit e5e81a6

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

Filesystem.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -737,15 +737,10 @@ private static function box(callable $func, ...$args)
737737
self::$lastError = null;
738738
set_error_handler(__CLASS__.'::handleError');
739739
try {
740-
$result = $func(...$args);
740+
return $func(...$args);
741+
} finally {
741742
restore_error_handler();
742-
743-
return $result;
744-
} catch (\Throwable $e) {
745743
}
746-
restore_error_handler();
747-
748-
throw $e;
749744
}
750745

751746
/**

0 commit comments

Comments
 (0)