Is there any advantages or uses cases to throw other thing that a std::exception( or a derivatives types).
For example throw 1;
or throw \"error\";
I can't think of any obvious reasons why a class derived from std::exception
wouldn't typically be better.
But the throw 1
or throw "Error"
are valid expressions, and they probably take a bit less "effort" creating, and there may be situations where this is a benefit. Throwing an exception
type exception from the constructor of exception
would probably not work very well, so there's one place.
However, it's probably more of a philosophical decision: Since throw
can be made to throw a any type of object, it's not a bad idea to allow it. The more restrictions you put on things in a language, the more you restrict the possible uses of a language.