473,513 Members | 2,677 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

STL and method failure

Hi,

I can't seem to find any documentation as to how
STL indicates method failure, whether by return
code or exception.

e.g how would I test for out of memory case
when inserting into a vector

Mark

Jul 22 '05 #1
5 1403
"Mark" <ms******@REMOVETHISBITbtinternet.com> wrote...
I can't seem to find any documentation as to how
STL indicates method failure, whether by return
code or exception.

e.g how would I test for out of memory case
when inserting into a vector


You should catch std::bad_alloc exception.

V
Jul 22 '05 #2
On Wed, 9 Jun 2004 01:48:04 +0000 (UTC), "Mark"
<ms******@REMOVETHISBITbtinternet.com> wrote:
Hi,

I can't seem to find any documentation as to how
STL indicates method failure, whether by return
code or exception.
If you pass in the wrong parameters, you generally get undefined
behaviour, not any exception. Few STL methods can actually fail of
their own accord for any reason other than memory exhaustion.
e.g how would I test for out of memory case
when inserting into a vector


All expected exceptions are generally documented with the functions
that throw them (e.g. vector::at). However, many functions can fail if
memory is exhausted. The out of memory case depends on the allocator
argument of the container. With std::allocator, you'll get
std::bad_alloc on failure. Mostly exceptions will come from your own
classes that the STL is using as template parameters - e.g. if your
copy constructor can throw, that will be propogated by the STL
functions.

You'll probably want to read the appendix on library exception safety
in recent editions of Stroustrup's book:
http://www.research.att.com/~bs/3rd_safe0.html
He's kindly posted the PDF online.

Tom
--
C++ FAQ: http://www.parashift.com/c++-faq-lite/
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
Jul 22 '05 #3
"Mark" <ms******@REMOVETHISBITbtinternet.com> wrote in message
news:ca**********@hercules.btinternet.com...
e.g how would I test for out of memory case
when inserting into a vector


Most operating systems these days do not offer a useful way of detecting
memory exhaustion. The reason is that they mostly use virtual memory, which
means that long before you run out of memory, you start doing huge amounts
of paging and the whole machine starts running incredibly slowly. Then the
user comes along and cancels the program.
Jul 22 '05 #4

Andrew Koenig wrote:

"Mark" <ms******@REMOVETHISBITbtinternet.com> wrote in message
news:ca**********@hercules.btinternet.com...
e.g how would I test for out of memory case
when inserting into a vector


Most operating systems these days do not offer a useful way of detecting
memory exhaustion. The reason is that they mostly use virtual memory, which
means that long before you run out of memory, ...


setrlimit(RLIMIT_AS, ...);

regards,
alexander.
Jul 22 '05 #5
> > > e.g how would I test for out of memory case
when inserting into a vector


Most operating systems these days do not offer a useful way of detecting
memory exhaustion. The reason is that they mostly use virtual memory, which
means that long before you run out of memory, ...


setrlimit(RLIMIT_AS, ...);


What do you mean? There is no such thing as "setrlimit", "RLIMIT_AS"
in Standard C++.

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
To iterate is human, to recurse divine.
-L. Peter Deutsch
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Jul 22 '05 #6

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

Similar topics

6
3006
by: VM | last post by:
In my Win app, I have an event that calls method myMethod.Process() which returns a struct. This method Process() is composed of several other methods: openDB(), checkDB, expireDB(), etc... and all these methods return 0 (Success) or 1 (Fail). If any of these methods return a 0, the process is cancelled. How can I return the 1 value...
3
2248
by: ticketdirector | last post by:
Hi, In the event viewer on our production web server (win2k3), I am seeing that if a call to the System.Net.Mail.SmtpClient.Send() function fails / throws an exception, it is popping up an assertion failure message box. But since this is a remote server, there is no logged in user, so the assertion failure message box is just sitting there...
0
2631
by: Marty Cruise | last post by:
I successfully deploy my application to 20 domain users. Only one new user is giving me a problem, although he can access all domain resources. When he clicks the installation link on the publish page, Framework 2.0 installs successfully, but then the application installation fails during the "Verifying Application Requirements" process. ...
4
2889
by: davehowey | last post by:
'Learning Python' by Lutz and Ascher (excellent book by the way) explains that a subclass can call its superclass constructor as follows: class Super: def method(self): # do stuff class Extender(Super): def method(self):
66
3551
by: Johan Tibell | last post by:
I've written a piece of code that uses sockets a lot (I know that sockets aren't portable C, this is not a question about sockets per se). Much of my code ended up looking like this: if (function(socket, args) == -1) { perror("function"); exit(EXIT_FAILURE); } I feel that the ifs destroy the readability of my code. Would it be
1
3860
by: noony | last post by:
Here is the error I get after calling a method (described below) : Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention. This is the code...
1
2043
by: =?Utf-8?B?Qi4gQ2hlcm5pY2s=?= | last post by:
(If I'm overlooking anything, please let me know.) First, my only concern is updating single records in a Detailsview using an ObjectDataSource. The target table has a timestamp field. Assume a single primary key. Create your xsd. Drag the table onto the xsd. Then manually edit the Update statement to simplify it. Essentially...
4
1256
by: =?Utf-8?B?WWFua2VlIEltcGVyaWFsaXN0IERvZw==?= | last post by:
I'm do meore and more with extention methods, totally cool. They are making life much easier for IU developers. I'm trying to add a return type of struct to a asp.net DropDownList of type struct. The idea is that if the conversion to say Int32 failed and a default value was used i can also return a Pass/Fail bool, int code to let the developer...
0
7269
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7177
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7559
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7542
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5701
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5100
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4756
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3248
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
1611
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.