minor #19617 Use try-finally where it possible (Koc)

This PR was merged into the 3.1 branch.

Discussion
----------

Use try-finally where it possible

| Q             | A
| ------------- | ---
| Branch?       | 3.1
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Just a minior refactoring for using PHP 5.5 feature.

Commits
-------

747ddf6 Use try-finally where it possible
This commit is contained in:
Fabien Potencier 2016-08-16 07:44:38 -07:00
commit e34426e105
3 changed files with 17 additions and 38 deletions

View File

@ -45,21 +45,15 @@ class AutowirePass implements CompilerPassInterface
$this->completeDefinition($id, $definition); $this->completeDefinition($id, $definition);
} }
} }
} catch (\Exception $e) { } finally {
} catch (\Throwable $e) { spl_autoload_unregister($throwingAutoloader);
}
spl_autoload_unregister($throwingAutoloader); // Free memory and remove circular reference to container
$this->container = null;
// Free memory and remove circular reference to container $this->reflectionClasses = array();
$this->container = null; $this->definedTypes = array();
$this->reflectionClasses = array(); $this->types = null;
$this->definedTypes = array(); $this->ambiguousServiceTypes = array();
$this->types = null;
$this->ambiguousServiceTypes = array();
if (isset($e)) {
throw $e;
} }
} }

View File

@ -215,20 +215,12 @@ class PropertyAccessor implements PropertyAccessorInterface
$value = $zval[self::VALUE]; $value = $zval[self::VALUE];
} }
} catch (\TypeError $e) { } catch (\TypeError $e) {
try { self::throwInvalidArgumentException($e->getMessage(), $e->getTrace(), 0);
self::throwInvalidArgumentException($e->getMessage(), $e->getTrace(), 0); } finally {
} catch (InvalidArgumentException $e) { if (PHP_VERSION_ID < 70000 && false !== self::$previousErrorHandler) {
restore_error_handler();
self::$previousErrorHandler = false;
} }
} catch (\Exception $e) {
} catch (\Throwable $e) {
}
if (PHP_VERSION_ID < 70000 && false !== self::$previousErrorHandler) {
restore_error_handler();
self::$previousErrorHandler = false;
}
if (isset($e)) {
throw $e;
} }
} }

View File

@ -119,23 +119,16 @@ abstract class AbstractDumper implements DataDumperInterface, DumperInterface
*/ */
public function dump(Data $data, $output = null) public function dump(Data $data, $output = null)
{ {
$exception = null;
if ($output) { if ($output) {
$prevOutput = $this->setOutput($output); $prevOutput = $this->setOutput($output);
} }
try { try {
$data->dump($this); $data->dump($this);
$this->dumpLine(-1); $this->dumpLine(-1);
} catch (\Exception $exception) { } finally {
// Re-thrown below if ($output) {
} catch (\Throwable $exception) { $this->setOutput($prevOutput);
// Re-thrown below }
}
if ($output) {
$this->setOutput($prevOutput);
}
if (null !== $exception) {
throw $exception;
} }
} }