Skip to content

Commit 0b56ae3

Browse files
committed
Merge pull request #91 from php-school/finally
Emit run.finish even if exception is thrown
2 parents 86104cf + 6d77eb4 commit 0b56ae3

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/ExerciseDispatcher.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,14 @@ public function run(ExerciseInterface $exercise, $fileName, OutputInterface $out
176176
$exercise->configure($this);
177177
$this->eventDispatcher->dispatch(new Event('run.start', compact('exercise', 'fileName')));
178178

179-
$exitStatus = $this->runnerFactory
180-
->create($exercise, $this->eventDispatcher)
181-
->run($fileName, $output);
179+
try {
180+
$exitStatus = $this->runnerFactory
181+
->create($exercise, $this->eventDispatcher)
182+
->run($fileName, $output);
183+
} finally {
184+
$this->eventDispatcher->dispatch(new Event('run.finish', compact('exercise', 'fileName')));
185+
}
182186

183-
$this->eventDispatcher->dispatch(new Event('run.finish', compact('exercise', 'fileName')));
184187
return $exitStatus;
185188
}
186189

0 commit comments

Comments
 (0)