I need an exception like UnSupportedOperationException in C++ but can't find one. I was hoping it will be in STL but seemingly its not there.Should I create one myself by deriving from STL exception class?
Why I need it?: I am implementing composite design pattern which requires throwing unsupportoperationexception in bases class. Jave has it but c++ don't.
Generally, you should avoid to create exception classes. Use the class which matches your case best, e.g.
throw std::runtime_error( "foo() is unsupported" );
Only if you want to catch an exception and you know how to handle the situation, you need to derive your own class. In that case, derive from the standard library's exception class which best matches your case. Check the exception categories offered.
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