A failure to handle exceptions

131 views
Skip to first unread message

James Moe

unread,
Mar 27, 2016, 8:30:15 AM3/27/16
to

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! ]

Martin Bonner

unread,
Mar 29, 2016, 8:10:17 AM3/29/16
to
That is not your complete program. (You have omitted the definition of
pmmsend_return_code_t at a minimum). Have you elided anything else?
If so I suspect that is where your problem lies. The other potential
problem might be that your constructor never initializes "txt" (but you
never use it either, so that *should* be alright).


--

Ralf Fassel

unread,
Mar 29, 2016, 2:40:09 PM3/29/16
to

* James Moe <jimoe...@sohnen-moe.com>
| gcc v3.3.5
--<snip-snip>--
| Am I missing anything? Or should I blame the compiler?

gcc 3.3.5 was released in September 2004, and I doubt it that anyone is
still working or even interested in gcc problems dating back that far.
Better retry using a current compiler version (and provide a compilable
example when you find the same error there).

HTH
R'


--
Reply all
Reply to author
Forward
0 new messages