It seems to me that it is rendundant information as the usage of the class will make it apparent that it is an exception. Furthermore, in PHP, the class must extend the Exception
class so it will be apparent that it is an exception when looking at the class on its own.
Despite this, devel开发者_如何学运维opers usually apply the suffix 'Exception'. Why is this?
I know of no binding rule for this, but I guess it simply makes sense.
class FileNotFound
could mean a number of things, while
class FileNotFoundException
makes the Exception character very clear.
Imagine two classes, InvalidIndex and InvalidIndexException. A class named InvalidIndex might be completely valid (e.g. to invalidate database indexes or something like that) and not related to an exception. If you now had an exception for invalid array indices you'd have a naming problem. By suffixing exception classes with Exception, you avoid name conflicts like that.
精彩评论