473,386 Members | 1,883 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Why "throw std::string" is not correct?

Below code cannot be compiled.
try
{
throw std::string;
}
catch(...)
{
}

While below is correct.
try
{
throw std::string();
}
catch(...)
{
}

Why doesn't standard C++ parse "throw std::string" as "throw
std::string()"?

Jul 22 '05 #1
2 2888

"Cheng Mo" <mo******@nospam.nospam> wrote in message
Below code cannot be compiled.
try
{
throw std::string;
std::string is name of a class.
}
catch(...)
{
}

While below is correct.
try
{
throw std::string();
std::string() creates an unnamed object.
}
catch(...)
{
}
It's legal to throw an object but not a class name.
Why doesn't standard C++ parse "throw std::string" as "throw
std::string()"?


They are different. That's the way language is designed, for more queries
news:comp.std.c++ should help you.

Sharad


Jul 22 '05 #2
Cheng Mo wrote:
Below code cannot be compiled.
throw std::string;
Throw takes an object as parameter, not a type.
'std::string' is a type, not an object.
While below is correct.
throw std::string();
'std::string()' is an object (of type 'std::string').
Why doesn't standard C++ parse "throw std::string" as "throw
std::string()"?


Why should it? There is a distinction between an object and
a type.
--
<mailto:di***********@yahoo.com> <http://www.dietmar-kuehl.de/>
<http://www.contendix.com> - Software Development & Consulting

Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: CoolPint | last post by:
Is there any way I can reduce the size of internal buffer to store characters by std::string? After having used a string object to store large strings, the object seems to retain the large...
7
by: ma740988 | last post by:
The string object value_f doesn't produce the right output. At issue, - I suspect - is the conversion from string to int with istringstream. An alternate approach? Thanks in advance #include...
13
by: Jacek Dziedzic | last post by:
Hi! <OT, background> I am in a situation where I use two compilers from different vendors to compile my program. It seems that recently, due to a misconfiguration, library conflict or my...
9
by: Fei Liu | last post by:
In Accellerated C++, the author recommends that in a header file one should not declare using std::string, using std::vector etc instead one should directly specify the namespace specifier in...
4
by: Bobrick | last post by:
Hi. I'm in the process of making a GUI for a function someone else wrote, and i've come across a type i'm unfamiliar with, namely "std::vector<unsigned char>". I need to get the contents of this...
10
by: lovecreatesbea... | last post by:
Is it correct and safe to compare a string object with "", a pair of quotation marks quoted empty string?If the string object: s = ""; does s contain a single '\'? Is it better to use...
13
by: arnuld | last post by:
/* C++ Primer 4/e * section 3.2 - String Standard Library * exercise 3.10 * STATEMENT * write a programme to strip the punctation from the string. */ #include <iostream> #include...
5
by: Eric Lilja | last post by:
Is there something "elegant" in the standard library I can use to perform a "shifted insert" in a std::string? Let me examplify what I mean with shifted insert. Say I have: std::string foo =...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.