Skip to content

Commit a8aa21b

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 0f7d897 + 826b083 commit a8aa21b

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

Tests/EventListener/DebugHandlersListenerTest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ public function testConfigure()
5050
try {
5151
$listener->configure();
5252
} catch (\Exception $exception) {
53+
} finally {
54+
restore_exception_handler();
55+
restore_error_handler();
5356
}
54-
restore_exception_handler();
55-
restore_error_handler();
5657

5758
if (null !== $exception) {
5859
throw $exception;
@@ -116,9 +117,10 @@ public function testConsoleEvent()
116117
try {
117118
$dispatcher->dispatch($event, ConsoleEvents::COMMAND);
118119
} catch (\Exception $exception) {
120+
} finally {
121+
restore_exception_handler();
122+
restore_error_handler();
119123
}
120-
restore_exception_handler();
121-
restore_error_handler();
122124

123125
if (null !== $exception) {
124126
throw $exception;

0 commit comments

Comments
 (0)