exception in string

Joined
Feb 12, 2008
Messages
108
Reaction score
0
Hello everyone,


I am reviewing the exception safety of some code and met with some issues about exception safety in string, which I can not find the answer at hand. I think the 3 code segments may all throw exceptions. Because the storage of string internal character data is on heap (using allocator for char?), so when there is low memory, there will be bad_alloc exception?

1. Initialization

Code:
string str1 = "Hello"; // or string str ("Hello");

2. Assignment

Code:
string str2 = str1; // str1 is another string object or reference.

3. Empty construction

Code:
string str;

I am not quite sure about (3).


thanks in advance,
George
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top