Skip to content

Throws its own exceptions#6

Open
maidmaid wants to merge 1 commit intodevelopfrom
feature/own-exceptions
Open

Throws its own exceptions#6
maidmaid wants to merge 1 commit intodevelopfrom
feature/own-exceptions

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