Naming exceptions


(Alexander Makarov) #1

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


(mahmud128) #2

FormattingFailedException?


#3

Are there any projects using such convention?


(Alexander Makarov) #4

Yes.

  1. Braintree
  2. Stripe

(Alexander Makarov) #5

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


#6

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.


(Alexander Makarov) #7

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

Note that it could be adjusted before release.


(Stefano Mtangoo) #8

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


(Serban Cristian) #9

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