-
-
Notifications
You must be signed in to change notification settings - Fork 102
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
Reorganize exceptions structure #32
base: master
Are you sure you want to change the base?
Conversation
return new self('No single currency for country ' . $countryCode . ': ' . implode(', ', $currencyCodes)); | ||
} | ||
} | ||
<?php |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something was wrong with the line endings here.
Hi, I know it's annoying to have PHPStorm complain about checked exceptions, however I'm not sure if I agree that |
In my PR
You just should validate input first. You also can got something like array or object from some input and raise \TypeError. But should you catch it? I don't think so. Also unchecked exceptions don't mean that you can catch it. You still can do it if you really want. |
Good point, I agree that there may be inconsistencies, but I'm still not sure which way is the right way to go. |
I like the idea to replace MoneyException base class with MoneyException interface 👍 |
I like the idea behind the logic exception, but maybe a runtime exception is better. I also find it quite annoying that I have to add a throws annotation to all my doc blocks. |
Does anyone know when this is going to be released? |
@BenMorel When will it be released? |
This will be released as soon as I know for sure which direction is the way to go :) |
4d81752
to
c82e106
Compare
Usually exceptions divide into checked and unchecked. It is more java concept, but also suitable for php world.
When
\LogicException
(unchecked) arises you don't usually want to catch and continue to work, better way is just show some error and fail fast. Because this exception means some bug in source code and only good way to deal with it - fix this bug.This is the reason why phpstorm skips
\LogicException
by default.My proposal is reorganisation money exceptions structure to make
MoneyMismatchException
andUnknownCurrencyException
unchecked by extending\LogicException
.Before:
What should I do? Write useless try-catch, or add
@throws
annotation (which will be a lie)After:
Phpstorm just skips this exception check.
Be aware, this changes is not really backward compatible!