Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ basic string exception

Tags:

c++

exception

If I just want to throw a string, isn't there a built in type somewhere so that I can just do

throw standard_exception("This is wrong!");

Or do I have to define such a standard exception that derives from exception myself? I know it is very simple to do so, I just thought this would be so common that it would be defined somewhere.

Thanks

like image 776
Cookie Avatar asked Jun 26 '26 06:06

Cookie


1 Answers

std::runtime_error and std::logic_error (both derived from std::exception) both have constructors that take strings and override the what() member function to return the provided string.

like image 97
James McNellis Avatar answered Jun 28 '26 19:06

James McNellis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!