Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6748853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:37:01+00:00 2026-05-26T12:37:01+00:00

There’s probably a Google search that’ll answer this question but for the life of

  • 0

There’s probably a Google search that’ll answer this question but for the life of me, I can’t think of one that doesn’t get millions of unrelated answers.

So,

In MSVC text inside quotes “like this” is taken, I think, as a std::string or, maybe, std::string&. In g++/gcc it always seems to be taken as const char*. True?

I found a code snippet I wanted to play with and it contains

if(NULL == key)
   throw exception("Empty key");

compiles just fine in MSVC/VC++(2008( but when I try it on g++ (4.4.3) I get

no matching functions for calls to std::exception::exception(const char&) 

I got this to work:

if (NULL == key)
{
   std::string   estr   ("Empty key");
   throw exception("Empty key");
}

But that’s just plain ugly.

This got me different errors:

std::string   estr   ("");
if (NULL == key)
{
   estr = "Empty key";
   throw exception("Empty key");
}

I have no clue what exception() expects as its input. I did find something that suggested std::string or maybe std::string& but I lost that page and the millions of unhelpful pages I’ve found since are, well, useless. Have all kinds of info on exception class, exception use,….

Short of my ugly fix, is there a simple way to tell g++ that “this is a std::string” not a const char& and still keep VC++ happy? (obviously I’m trying to do cross compilable code from single source.)

And for that matter, how id

   throw exception("Empty key");

different from

   throw "Empty key";

Thanks,

Wes

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T12:37:02+00:00Added an answer on May 26, 2026 at 12:37 pm

    A string literal always has the type of an array of char, with a size just large enough to contain the characters in the literal with a null terminator. So "Empty key" has the type char[10]. This can be implicitly converted to either char const * or std::string if required.

    The error is because exception is intended as a base class for exception types, not something you instantiate directly. You should throw one of the types defined in <stdexcept> such as std::runtime_error (which can be constructed using a string), or define your own type that inherits std::exception and overrides what().

    I’m guessing that Microsoft has added a non-standard constructor to std::exception. They like to extend the language in strange ways.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There are posts that touch on this question, but no one that I can
There seems to be a similar question to this on here but with the
There is no doubt that MonoTouch is one of the great cross-compiler(s). Similarly, SenchaTouch
There was a thread on this in comp.lang.javascript recently where victory was announced but
There are many tutorials that talk about deleting index.php from the url. But I
There must be a simple solution to this, but after 4 hours of browsing
There's a lot of reading on self referencing problems, but I can't seem to
There are things like f.call(...) f.apply(...) But then there's this (1, alert)('Zomg what is
There is previous little on the google on this subject other than people asking
There's a common error that gets thrown by the Visual C Runtime: This application

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.