public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* middle-end/8405: GCC 3.2: 'throw "exception";' not caught by catch
@ 2002-10-30  9:16 dobrynin
  0 siblings, 0 replies; 2+ messages in thread
From: dobrynin @ 2002-10-30  9:16 UTC (permalink / raw)
  To: gcc-gnats


>Number:         8405
>Category:       middle-end
>Synopsis:       GCC 3.2: 'throw "exception";' not caught by catch
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Oct 30 09:16:02 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     Nickolai Dobrynin
>Release:        GCC 3.2
>Organization:
>Environment:
Sun OS, Windows 2000 with Pentium 3, Cygwin under W2000/P3
>Description:
Calling the following function

void f() throw(std::string)
{
  throw "exception";
}

aborts the program. It would seem that the char array "exception" must be coerced to a string-object, but this is clearly not the case here.

By the way, GCC 2.95 has the same behavior, and I didn't check the earlier versions.

I have no certainty as to whether this presents a bug or just a feature, but in either case it is quite frustrating to deal with.
>How-To-Repeat:
#include <string>
#include <iostream>


void f() throw(std::string)
{
  throw "exception";
}


int main()
{
  try {
    f();
  }
  catch(...) {
    std::cout << "Exception caught." << std::endl;
    // The string exception does not get caught,
    // which aborts the program.
  }


  return 0;
}
>Fix:
An obvious work-around it to use 'throw(const char *)' instead of 'throw(std::string)' as the exception specification for the function 'f'. Alternatively, we could use something like
'throw std::string("exception");' to raise the exception.
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="bug.cpp"
Content-Disposition: inline; filename="bug.cpp"

#include <string>
#include <iostream>


void f() throw(std::string)
{
  throw "exception";
}


int main()
{
  try {
    f();
  }
  catch(...) {
    std::cout << "Exception caught." << std::endl;
    // The string exception does not get caught,
    // which aborts the program.
  }


  return 0;
}


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: middle-end/8405: GCC 3.2: 'throw "exception";' not caught by catch
@ 2002-10-30 12:55 bangerth
  0 siblings, 0 replies; 2+ messages in thread
From: bangerth @ 2002-10-30 12:55 UTC (permalink / raw)
  To: dobrynin, gcc-bugs, gcc-prs, nobody

Synopsis: GCC 3.2: 'throw "exception";' not caught by catch

State-Changed-From-To: open->closed
State-Changed-By: bangerth
State-Changed-When: Wed Oct 30 12:55:51 2002
State-Changed-Why:
    Not a bug. An exception specification attached to a function
    does not imply any conversion of the exception actually thrown.
    
    You have to throw std::string("something").
    
    The program aborts since the exception actually thrown
    does not match the exception specification of the function.
    I don't know it right off my head what happens exactly in
    this case (look it up in any book on C++), but this leads
    either to raising a special exception or calling
    uncaught_exception or some such function. In any case,
    the catch(...) clause is not invoked in this case.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=8405


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-10-30 20:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-30  9:16 middle-end/8405: GCC 3.2: 'throw "exception";' not caught by catch dobrynin
2002-10-30 12:55 bangerth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).