• A failure to handle exceptions

    From James Moe@21:1/5 to All on Sun Mar 27 07:29:31 2016
    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! ]

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Martin Bonner@21:1/5 to James Moe on Tue Mar 29 07:02:43 2016
    On Sunday, 27 March 2016 14:30:15 UTC+2, James Moe wrote:
    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);

    }

    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).


    --
    [ See http://www.gotw.ca/resources/clcm.htm for info about ]
    [ comp.lang.c++.moderated. First time posters: Do this! ]

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ralf Fassel@21:1/5 to All on Tue Mar 29 13:38:36 2016
    * James Moe <jimoeDESPAM@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'


    --
    [ See http://www.gotw.ca/resources/clcm.htm for info about ]
    [ comp.lang.c++.moderated. First time posters: Do this! ]

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)