Naming exceptions

Same as with interfaces, some experiments were conducted to check if not using Exception suffix is good or not.

This time it is more controversial. If named carefully, we can get names like FromattingFailed i.e. convention could be:

  1. Past simple tense. Indicates that it happened.
  2. Should indicate something bad happened.

What do you think about it?

What exception naming style do you prefer?

  • I prefer to use suffix, i.e. FormattingException
  • I prefer no suffix i.e. FormattingFailed

0 voters

FormattingFailedException?

Are there any projects using such convention?

Yes.

  1. Braintree
  2. Stripe

Also, here’s an article (one of many) that describes rationale behind such experiment: https://mnapoli.fr/approaching-coding-style-rationally/

Although I can understand this for interfaces, for exceptions you get exactly opposite result - name no longer represents “what it is”. FormatingFailed is not a thing, it is a sentence. It contradicts with general convention that object represents something, so you’re using nouns to describe it.

2 Likes

OK. Based on voting here and at the Russian community forums

Note that it could be adjusted before release.

1 Like

That’s the real deal! I completly agree with @rob006

I think use Exception suffix: https://symfony.com/blog/new-in-symfony-4-1-exception-improvements

1 Like