Разве так нельзя писать?
-----------------------------------------------------------------
#include <exception>
#include <iostream>
class my_error: public std::exception {
private:
std::string m_err;
public:
my_error(const std::string &err) throw() : m_err(err) {}
~my_error() throw() {}
virtual const char* what() const throw() { return m_err.c_str(); }
};
int main(void)
{
try {
throw my_error("FATAL ERROR");
}
catch(my_error &e) {
std::cout << "exception handled: " << e.what() << std::endl;
}
return 0;
}
-----------------------------------------------------------------
Если компилирую кросскомпилятором sh4-linux-gcc v3.0.3 - валится по сегфолту на throw
Компилирую gcc v3.4.3 - все работает.
Это работает и там и там:
-----------------------------------------------------------------
#include <exception>
#include <iostream>
class my_error: public std::exception {
private:
const char *m_err;
public:
my_error(const char *err) throw() : m_err(err) {}
~my_error() throw() {}
virtual const char* what() const throw() { return m_err; }
};
int main(void)
{
try {
throw my_error("FATAL ERROR");
}
catch(my_error &e) {
std::cout << "exception handled: " << e.what() << std::endl;
}
return 0;
}
-----------------------------------------------------------------