Throwable: A different approach#1282
Throwable: A different approach#1282trowski wants to merge 2 commits intophp:masterfrom trowski:throwable
Conversation
EngineException, TypeException, and ParseException were renamed to EngineError, TypeError, and ParseError. Each now extends Error. Exception and Error extends Throwable, the common exception class previously called BaseException.
|
Java's Exception hierarchy sucks. This is the best comment I can give. I'm sorry if it sounds harsh but it's just the truth. We definitely don't want to emulate something that is universally hated by the whole java community. |
Java's exceptions suck because of checked and unchecked exceptions. This PR does nothing to implement any craziness like that, because I agree, the last thing we want to do is emulate Java. I regret even mentioning the comparison. All this PR does is push a new class |
|
I think Java problems mainly come from checked exceptions and the boilerplate that is involved in this. I don't see this patch having the same problems. |
|
Closing as #1284 supersedes this PR. |
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:
BaseExceptionhas been renamed toThrowableand a new classErrorextendingThrowableis 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:
Erroris only thrown due to problems that previously raised errors.Errornaming scheme chosen to avoid confusion. Example: why wouldcatch (Exception $e)not catch an object namedEngineException?Cons:
Exceptionin the name.Errorclasses 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
Exceptionbecause 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.