This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

middle-end/8405: GCC 3.2: 'throw "exception";' not caught by catch


>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;
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]