I am not sure what caused this question, since you can choose the "application" in those cases when you consider it necessary.
The purpose of object exclusion is to indicate that an exception has occurred, and, as a rule, to carry with it specific information about the exception from the thrower to the handler. If one type is sufficient for your purpose, you can use this type as an exception type. If you want, you can throw away int values, std::string values and everything else. It is completely up to you.
If all you want to transfer from a thrower to a handler is an int value, then the int type will serve this purpose as an exception type. That is all that is needed.
C ++ does not impose any specific requirements on types that you can throw. For this reason, there really is no such thing as an “exception” type or a “no exception” type. What is the "type of exception" and what is not is determined by you and only you in your code. You can drop something as long as you know how to catch it and how to interpret what you caught.
The first advantage of using class types to represent exceptions is that class types are freely defined by the user, that is, you can easily define as many types of exceptions as you want. Then you can use many independent, non-interfering "thread" exceptions that throw and catch only exceptions of their respective types.
The second advantage of using class types to represent exceptions is that class types are easily extensible. That is, at any time you can add additional information about the "payload" to your type of exception, and this payload will be transferred from the place where the exception was selected until the moment it was caught and processed.
If you are not interested in any of these benefits, you can simply output and catch values of type int to represent your exceptions. That will work. But I'm pretty sure that you will quickly come across the limitations of this approach in terms of service and extensibility.
AnT
source share