Article View: comp.std.c++
Article #3552Re: Who gets out of memory exception?
From: J. Kanze
Date: Thu, 29 Feb 1996 16:00
Date: Thu, 29 Feb 1996 16:00
43 lines
2686 bytes
2686 bytes
In article <TOM.96Feb28161011@amber.ssd.csd.harris.com> tom@ssd.hcsc.com
(Tom Horsley) writes:
|> Someone showed me the "function try blocks" in the draft standard today, and
|> I immediately began to wonder what happens if the function in question is
|> a constructor and one of the exceptions I catch is "out of memory". If I
|> have something like:
|> Fred::Fred(...) try : initializers... {
|> code goes here...
|> } catch ...
|> And then I say "new Fred" and run out of memory.
|> I know some existing C++ implementations call the memory allocation code from
|> inside the constructor and others call it from the place in the code where
|> 'new' was invoked. So in different implementations today, the exception
|> might actually occur in the caller or the constructor itself.
Where the compiler actually generates the call to the memory allocator
is irrelevant. The compiler is required to generate code whose
`observable behavior' is as if the call to the memory allocator preceded
the call to operator new.
|> Does the standard say who gets the memory exception? Or is running out of
|> memory even an exception? Or is this simply left undefined?
The exception (bad_alloc) is thrown by operator new. The first place it
becomes catchable is in the new expression. The constructor is never
called (as far as the observable behavior is concerned).
--
James Kanze (+33) 88 14 49 00 email: kanze@gabi-soft.fr
GABI Software, Sarl., 8 rue des Francs Bourgeois, 67000 Strasbourg, France
Conseils, études et réalisations en logiciel orienté objet --
-- A la recherche d'une activité dans une region francophone
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
Technical Details
Message-ID:
<KANZE.96Feb29160957@gabi.gabi-soft.fr>Path:
arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamageReferences:
<TOM.96Feb28161011@amber.ssd.csd.harris.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamage From: kanze@gabi-soft.fr (J. Kanze) Newsgroups: comp.std.c++ Subject: Re: Who gets out of memory exception? Followup-To: comp.std.c++ Date: 29 Feb 1996 16:00:42 GMT Organization: GABI Software, Sarl. Approved: clamage@eng.sun.com (comp.std.c++) Message-ID: <KANZE.96Feb29160957@gabi.gabi-soft.fr> References: <TOM.96Feb28161011@amber.ssd.csd.harris.com> NNTP-Posting-Host: taumet.eng.sun.com Content-Type: text X-Nntp-Posting-Host: gabi.gabi-soft.fr In-Reply-To: tom@ssd.hcsc.com's message of 28 Feb 1996 13:18:52 PST Content-Length: 1657 X-Lines: 35 Originator: clamage@taumet