Throwable: A different approach #1282
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request is based on the Throwable pull request by @sebastianbergmann, but it takes a slightly different approach. This is based on comments made in that pull request as well as some comments on the internals mailing list.
I'm proposing a modification to the exception hierarchy for PHP 7:
BaseException
has been renamed toThrowable
and a new classError
extendingThrowable
is used for issues that previously raised errors in PHP 5. This scheme is similar to the exception hierarchy in Java.catch(Exception $e)
does not catch any previously uncaught exceptions.catch(Error $e)
can be used to catch only interpreter errors.catch(Throwable $e)
can catch any exception or error class.Pros:
Error
is only thrown due to problems that previously raised errors.Error
naming scheme chosen to avoid confusion. Example: why wouldcatch (Exception $e)
not catch an object namedEngineException
?Cons:
Exception
in the name.Error
classes in the global namespace would need to be renamed.Edit: I would rather a distinction wasn't made between normal exceptions and errors, but unfortunately we probably should for BC. Exceptions thrown by the engine shouldn't directly extend
Exception
because they would cause BC issues, being unintentionally caught bycatch (Exception $e)
. Since this distinction must be made, I think it's better to make the distinction clearer rather than try and obfuscate it and cause confusion for users.