gcc v3.3.5
When the exception is thrown "throw error_handler(pmmsend_rc)" the
program aborts (SIGABRT). The constructor completes; the abort occurs
after initialization, presumably in the catch() statement.
I can see no reason for this unreasonable behavior.
Am I missing anything? Or should I blame the compiler?
class error_handler {
private:
const char * txt;
pmmsend_return_code_t rc;
public:
error_handler (pmmsend_return_code_t err_rc = RC_NO_ACTION) { rc =
err_rc; }
pmmsend_return_code_t return_code () const { return rc; };
const char * return_text () {
switch (rc)
{
default: txt = "Unhandled Error";
case RC_NO_ERROR: txt = "No Error";
case RC_NO_ACTION: txt = "Nothing happened";
case RC_HELP: txt = "Help displayed";
// more to come...
}
return txt;
}
};
int main (int argc, char *argv[])
{
pmmsend_return_code_t pmmsend_rc = RC_NO_ACTION;
prog_args_t prog_args;
try {
if (RC_NO_ERROR != pmmsend_rc)
throw error_handler(pmmsend_rc);
// build message
// send message
}
catch (const error_handler & ex) {
cerr << "Error: " << ex.return_code() << endl;
}
catch (...) {
cerr << "Splat! The unhandled error." << endl;
}
exit(pmmsend_rc);
}
--
James Moe
jmm-list at sohnen-moe dot com
[ See
http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]