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

Make exception message configurable for NoResultException #1484

Closed
wants to merge 2 commits into from

Conversation

haeber
Copy link
Contributor

@haeber haeber commented Jul 31, 2015

Currently it's not possible to use a custom exception message for the NoResultException. It would be great to use a custom one. For example you can define what specific result was expected or with what query it was executed, let's say you want to find members with a select query. Then it would be great if the message could be 'No members found for query.', instead of the default message.

This change is backward compatible, because it uses the current message as default value for message. Furthermore it's now possible to loop the parameters $code and $prevision exception throw this NoResultException.

Thanks for the hint Koc.

Currently it's not possible to use a custom exception message for the NoResultException. It would be great to use a custom one. For example you can define what specific result was expected or with what query it was executed, let's say you want to find members with a select query. Then it would be great if the message could be 'No members found for query.', instead of the default message.

This change is backward compatible, because it checks for emptiness of the message, and only if it's not empty it uses the custom message. Furthermore it's now possible to loop the parameters $code and $prevision exception throw this NoResultException.
@doctrinebot
Copy link

Hello,

thank you for creating this pull request. I have automatically opened an issue
on our Jira Bug Tracker for you. See the issue link:

http://www.doctrine-project.org/jira/browse/DDC-3856

We use Jira to track the state of pull requests and the versions they got
included in.

*/
public function __construct()
public function __construct($message = '', $code = 0, \Exception $previous = null)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just add $message = 'No result was found for query although at least one row was expected.', here instead of checks in the constructor body?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. this is the best and most simple solution.

@Ocramius
Copy link
Member

Ocramius commented Aug 1, 2015

I don't see a reason to change this, since this exception should only be thrown from the internal scope.

@Ocramius
Copy link
Member

While I understand that you have your own use-case for customizing the exception message, you should instead use your own exception class/interface rather than relying on the ORM ones.

This is indeed a limitation caused by the ORM not having proper exception marker interfaces right now ( doctrine/common#681 )

@Ocramius Ocramius closed this Dec 11, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants