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, developers usually apply the suffix 'Exception'. Why is this?
That a class represents an exception should also be obvious either by its parentage or by its name. The name should represent whatever the problem is, and should do so directly and specifically. To add Exception to the end is either redundant — so remove it — or an indication of a poor name — so rename it.
The class Exception and its subclasses are a form of Throwable that indicates conditions that a reasonable application might want to catch. The class Exception and any subclasses that are not also subclasses of RuntimeException are checked exceptions.
Exceptions Hierarchy in Java The Exception class presents all the Exceptions that you might need to handle while working with the Java programming language. Some commonly known and encountered examples of such Exceptions include NullPointerException, ClassNotFoundException, IllegalArgumentException, etc.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With