Skip to content
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

Throws its own exceptions #6

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open

Conversation

maidmaid
Copy link
Member

@maidmaid maidmaid commented Dec 13, 2021

I'm writting a validator based on exceptions thrown by LocalDateInterval but we need at the moment to catch Webmozart exceptions to handle domain errors.

try {
    LocalDateInterval::parse($text);
} catch (\Gammadia\DateTimeExtra\Exceptions\IntervalParseException $e) {
    // handles parsing errors
} catch (\Webmozart\Assert\InvalidArgumentException $e) {
    // handles domain errors
}

This PR throws its own exceptions when it's domain specific and continues to call Webmozart namespaced exception when a error has to be handle in development process.

catch (\Gammadia\DateTimeExtra\Exceptions\IntervalParseException $e) { // handles parsing errors }
catch (\Gammadia\DateTimeExtra\Exceptions\InvalidArgumentException $e) { // handles domain errors }

A base exception can also be caught for generic purpose :

catch (\Gammadia\DateTimeExtra\Exceptions\ExceptionInterface $e) {}

{
protected static function reportInvalidArgument($message)
{
throw new InvalidArgumentException($message);
Copy link
Member Author

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant