Skip to content

use try-finally when possible #15949

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 28, 2015
Merged

use try-finally when possible #15949

merged 1 commit into from
Sep 28, 2015

Conversation

Tobion
Copy link
Contributor

@Tobion Tobion commented Sep 28, 2015

Q A
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Tests pass? I hope
Fixed tickets n/a
License MIT
Doc PR n/a

Found those with regex catch \(\\Exception[^\}]+throw \$

@@ -74,13 +74,10 @@ public function load($resource, $type = null)

try {
$collection = parent::load($resource, $type);
} catch (\Exception $e) {
} finally {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nicolas-grekas I assume this hack also works with finally, i.e. fatal errors are skipping it. I tried to test it as described in #14342. And it had the same result. So this code change didn't change the outcome of the exception page. But it was kinda strange anyway as there was a second error below the real one:

FatalErrorException in TraceableEventDispatcher.php line 357:
Error: Cannot use object of type Symfony\Component\EventDispatcher\Debug\WrappedListener as array

in vendor\symfony\symfony\src\Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher.php at line 357

@fabpot
Copy link
Member

fabpot commented Sep 28, 2015

Thank you @Tobion.

@fabpot fabpot merged commit 49edef2 into symfony:master Sep 28, 2015
fabpot added a commit that referenced this pull request Sep 28, 2015
This PR was merged into the 3.0-dev branch.

Discussion
----------

use try-finally when possible

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | I hope
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

Found those with regex `catch \(\\Exception[^\}]+throw \$`

Commits
-------

49edef2 use try-finally when possible
@lyrixx
Copy link
Member

lyrixx commented Sep 28, 2015

@fabpot finally does not work on PHP 5.5.

refs: https://bugs.php.net/bug.php?id=67047

ihmo, symfony should never use finally, except if we bump the requirements on php 5.6

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Sep 28, 2015 via email

@lyrixx
Copy link
Member

lyrixx commented Sep 28, 2015

but we must have this issue in mind.

that's why I think it's saver to recall: "never use it".
Because some people that are not aware of this bug could copy / paste symfony code, or mimic it and hit that bug.

Anyway, I may be too "strict" and may be it's better to be allow it when it's really safe. Don't know ;)

But again, all deciders should be aware of this bug to not merge some PR that trigger autoload.

@Tobion
Copy link
Contributor Author

Tobion commented Sep 28, 2015

@lyrixx thanks for pointing out. But as using autoloading in finally is an edge case, it should not prevent us using finally. It's an uncommon case because usually you do something in finally that you already accessed before (a variable, class or whatever to revert state). So autoloading there should not happen.

@Tobion Tobion deleted the try-finally branch September 28, 2015 13:54
@lyrixx
Copy link
Member

lyrixx commented Sep 28, 2015

@Tobion I totally agree with you ;) In theses case there is no issue. But image this piece of code:

try {
  // ..
} finally {
  if (true) {
    throw new NotYetLoadedException();
  }
}

;)

fabpot added a commit that referenced this pull request Nov 26, 2015
This PR was merged into the 3.0-dev branch.

Discussion
----------

[DI] use try-finally for container

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

Continuation of #15949

Commits
-------

1ab7316 [DI] use try-finally for container
This was referenced May 12, 2016
fabpot added a commit that referenced this pull request May 23, 2016
This PR was merged into the 2.7 branch.

Discussion
----------

Catch \Throwable

| Q             | A
| ------------- | ---
| Branch?       | 2.7, 2.8, 3.0
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | Yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

Related #18765, #15949
Depends on #18812

Commits
-------

103526b Catch \Throwable
fabpot added a commit that referenced this pull request May 23, 2016
This PR was merged into the 2.8 branch.

Discussion
----------

Catch \Throwable

| Q             | A
| ------------- | ---
| Branch?       | 2.8, 3.0
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | Mostly!
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

The first commit is based on #15949
Depends on #18813, #18812

----

I'm new to symfony, so I'm not sure where are all the places where it makes sense to actually catch the throwable and where not. I added most places that seemed logical and when I wasn't sure, I added it anyway. I'm hoping you guys (and girls?) can point out the places where the catch should not be added, I'll fix it and then I can create several PR's for the older branches. A lot of this IMHO should go also to 3.0.

Commits
-------

de671f4 Catch \Throwable
symfony-splitter pushed a commit to symfony/dependency-injection that referenced this pull request May 23, 2016
This PR was merged into the 2.8 branch.

Discussion
----------

Catch \Throwable

| Q             | A
| ------------- | ---
| Branch?       | 2.8, 3.0
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | Mostly!
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

The first commit is based on symfony/symfony#15949
Depends on symfony/symfony#18813, symfony/symfony#18812

----

I'm new to symfony, so I'm not sure where are all the places where it makes sense to actually catch the throwable and where not. I added most places that seemed logical and when I wasn't sure, I added it anyway. I'm hoping you guys (and girls?) can point out the places where the catch should not be added, I'll fix it and then I can create several PR's for the older branches. A lot of this IMHO should go also to 3.0.

Commits
-------

de671f4 Catch \Throwable
nicolas-grekas added a commit that referenced this pull request May 30, 2016
This PR was squashed before being merged into the 2.3 branch (closes #18812).

Discussion
----------

Catch \Throwable

| Q             | A
| ------------- | ---
| Branch?       | 2.3, 2.7, 2.8, 3.0
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | Yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

Related #18765, #15949

Commits
-------

893cf00 Catch \Throwable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants