Skip to content

Conversation

@SjorsO
Copy link
Contributor

@SjorsO SjorsO commented Jan 14, 2021

This is a follow-up on #35888

You can now pass throw_if and throw_unless a message as the second parameter, similar to the report function (which was changed in #35803):

// Currently:
throw_if($sometingIsWrong, new RuntimeException('something wrong with user '.$user->id));

// With this PR:
throw_if($sometingIsWrong, 'something wrong with user '.$user->id);

If the message passed is an existing class, that will be used as the exception instead:

throw_if($somethingIsWrong, LogicException::class);

And the newly added default parameter allows you to also do this, if you're not interested in a custom message:

throw_if($somethingIsWrong);

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.

2 participants