In general, this is because your catch block will not catch the exception that you throw if you leave const.
However, throwing a type without exception is considered a bad form; consider throwing std::runtime_error or another type derived from std :: exception. You can build most of them with a string and get the message from the what() property.
You should still grab them using the const link to prevent copying and modifying the caught object (which is by no means useful):
try { throw runtime_error( "full stack" ); } catch( const runtime_error & x ) { cout << x.what(); } catch( const exception & x ) { // catch other exceptions derived from this base class. }
Stevelove
source share