On Sunday, 27 March 2016 02:47:19 UTC+2, James Moe wrote:
> gcc v3.3.5
On what platform?
>
> 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?
Impossible (I will explain at end) to tell from your post but there is
always little chance of compiler defect.
The gcc 3.3 is over 10 years old version. If it is really an issue
with it and it was not fixed in gcc v3.3.6 then it will be likely
never fixed and so you have to work around of it.
Better take gcc 4.9.3 or 4.8.5 if you don't want to risk with the
bleeding edge 5. series. Likelihood of compiler defect to be fixed
(if found) is lot greater with newer compilers.
Do not erase #includes and declarations and other important things
if you post a test. Always try the test code if it manifests your
problem or not.
>
> class error_handler {
> private:
> const char * txt;
> pmmsend_return_code_t rc;
'pmmsend_return_code_t' undefined, I assume enum.
>
> public:
> error_handler (pmmsend_return_code_t err_rc = RC_NO_ACTION) { rc =
> err_rc; }
The 'txt' member uninitialized. U
> pmmsend_return_code_t return_code () const { return rc; };
>
> const char * return_text () {
> switch (rc)
> {
> default: txt = "Unhandled Error"; beak;
The 'beak' is unknown identifier.
> case RC_NO_ERROR: txt = "No Error"; break;
> case RC_NO_ACTION: txt = "Nothing happened"; break;
> case RC_HELP: txt = "Help displayed"; break;
> // 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;
Unknown type 'prog_args_t' and unused variable 'prog_args'.
>
> try {
> if (RC_NO_ERROR != pmmsend_rc) // Make it fail
> 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);
replace 'exit' with 'return'.
>
> }
Can't reproduce your error. Highly likely you edited its reason away.
Keywords like 'beak' indicate that you never attempted to compile and
run posted code. But it may also be that compiler contained a defect.
IOW we are not psychic, sorry.