Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I need UnSupportedOperationException in C++

Tags:

c++

exception

stl

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.

like image 964
zar Avatar asked Oct 26 '25 05:10

zar


1 Answers

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.

like image 94
Daniel Frey Avatar answered Oct 28 '25 17:10

Daniel Frey