vendredi 26 mars 2021

Why " throw" will dsiplay a warning?

#include <iostream>
#include <sstream>

using std::string;
using std::cout;
using std::endl;
using std::ostringstream;

class illegalParameterValue {

private:
    string message;
public:
    illegalParameterValue() : message("Illegal parameter value") {}
    explicit illegalParameterValue(const char* theMessage) {message = theMessage;}
    void outputMessage() {cout << message << endl;}

};

int main() {

    ostringstream s;
    s << "index = " << 1 << " size = " << 2;
    throw illegalParameterValue(s.str().c_str());

    return 0;
}

I just use some code like this, but the "throw" will remind some warnings which called "Clang-Tidy: Throwing an exception whose type 'illegalParameterValue' is not derived from 'std::exception'", how can I solve this problem?

Aucun commentaire:

Enregistrer un commentaire