Hi
I wrote some classes inheriting from <exception> in the following way:
Code:
class NoFile : public exception
{
public:
NoFile();
NoFile(string);
NoFile(const NoFile &);
virtual ~NoFile();
NoFile operator=(const NoFile &);
virtual const char* what() const;
const char* getName() const;
private:
const string reason;
string fileName;
};
And I use it in other files like that:
Code:
try
{
ifstream inp(inputName);
if(inp.is_open() == true)
{
//do something
}
else
{
throw NoFile(this->inputName);
}
}
catch(const NoFile &e)
{
cerr << "Caught exception: " << e.what() << ": " << e.getName() << endl;
cerr << "Returning to main menu" << endl << endl;
}
There are some more, but written in the same way so I guess there is no need to post them here. Anyway, the code for the entire program compiles without any problems in Visual Studio 2010 but the g++ compiler gives me millions of errors, most of them of this kind:
Code:
error: looser throw specifier for 'virtual const char* NoFile::what() const
Why this happens? Do VS and g++ have different implementations of <exception>? How to avoid these errors?