bizarre exception problem

llewelly@xmission.com llewelly@xmission.com
Fri May 21 18:40:00 GMT 2004


Jeremy Sanders <jss@ast.cam.ac.uk> writes:

> Hi -
> 
> Maybe someone could tell me why this exception isn't caught? I'm not
> sure whether it's a compiler bug. It used to work under gcc-2.96
> (RedHat). It's a snippet as I can't seem to get it to fail if I
> compile it by itself...
> 
>    void param::interpret_and_catch()
>    {
>      try {
>        throw except_invalid_at_file("foo");
>        interpret();
>      }
>      catch(const except_invalid_at_file e) {

I don't know if this is causing you problems or not, but you should
    catch by reference and not by value.

>        cerr << "Cannot open parameter file " << e() << "\n\n";
>        show_autohelp();
>      }
>      catch(const except_returnstr e) {
>        cerr << "Option " << e() << " invalid\n\n";
>        show_autohelp();
>      }
>    }
> 
> where:
> 
>    class except
>    {
>    public:
>    };
> 
>    class except_returnstr : public except
>    {
>    public:
>      except_returnstr(const std::string& uswitch) : m_switch(uswitch) {}
>      const std::string &operator()() const { return m_switch; }
>    private:
>      const std::string m_switch;
>    };
> 
>    class except_undef_switch : public except_returnstr
>    {
>    public:
>      except_undef_switch(const std::string &uswitch)
>        : except_returnstr(uswitch) {}
>    };

Please try to submit a short-but-complete example which will compile
    and reproduce your problem when run. In particular, you provide no
    definition for except_invalid_at_file. 



More information about the Gcc-help mailing list