[8.x] Model::delete throw LogicException not Exception #36914
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue
Currently eloquent model->delete() checks to see if a primary key is set on the model and throws a top level Exception if missing. This causes many static analysis tools to suggest using try catch anytime a model is deleted. Since this exception is only thrown when there is a mistake in the code (not setting the primary key) it could be changed to throw a LogicException instead.
Change
This PR changes the exception thrown by Model::delete() from \Exception to \LogicException.
Why logic exception?
Static analysis tools typically consider LogicException to be unchecked and won't suggest callers use try catch. This should reduce the amount of unnecessary try catch blocks in those projects.
Will this break anything?
Since LogicException extends Exception any user code that used to check for Exception will still work.