This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: bizarre exception problem
- From: llewelly at xmission dot com
- To: Jeremy Sanders <jss at ast dot cam dot ac dot uk>
- Cc: gcc-help at gcc dot gnu dot org
- Date: 21 May 2004 12:40:33 -0600
- Subject: Re: bizarre exception problem
- References: <Pine.LNX.4.60.0405211857540.18611@xpc5.ast.cam.ac.uk>
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.