public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: dobrynin@cs.uwm.edu
To: gcc-gnats@gcc.gnu.org
Subject: middle-end/8405: GCC 3.2: 'throw "exception";' not caught by catch
Date: Wed, 30 Oct 2002 09:16:00 -0000	[thread overview]
Message-ID: <20021030171310.32015.qmail@sources.redhat.com> (raw)


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


             reply	other threads:[~2002-10-30 17:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-10-30  9:16 dobrynin [this message]
2002-10-30 12:55 bangerth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20021030171310.32015.qmail@sources.redhat.com \
    --to=dobrynin@cs.uwm.edu \
    --cc=gcc-gnats@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).