The creators of Java and .Net decided to use the TYPE of the created exception object to determine when it should be caught and when it should be considered allowed, a constructive solution, probably motivated by the fact that C ++ handles exceptions. Although C ++ exception handling has been improved in many ways from what it was before, its use of the type of an exception object as a primary means of determining which exceptions were caught is not one of its best features.
Since the catching exception is controlled by the type of exception, there is no standard means for the exception to indicate whether the failed operation changed the state of any objects in the system, or whether the failure was caused by the fact that the objects are in a damaged state (unlike the state, which, although it may be unexpected caller and incompatible with the passed parameters, otherwise it would be considered that the called method is completely legal). In many cases, if, in response to a userβs request, the system calls a method that tries to do something and cannot, but this method does not adversely affect the state of any object, and the problem is not caused by the object, the damaged state is often better simply inform the user that the requested action cannot be completed and continued. Unfortunately, there is no way to distinguish βharmlessβ exceptions from the above types from those that indicate serious system-wide problems. Although 99% of exceptions are likely to be relatively harmless, a small portion will be caused by conditions that could lead to corruption of documents. If the open document was damaged, it might be better if the program crashed instantly rather than replacing a good copy on the damaged disk.
If you throw custom exceptions, you can include properties in the type of exception, which will allow the code to make it a little more useful to decide what to do with the exception. Unfortunately, many exceptions that can be thrown, harmless or not, will not include such properties.
source share