Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #41505

Re: C++ exceptions are broken.

Message-Id <20160313124838.377cf0fcbce06a95bb9167ff@speakeasy.net>
Newsgroups comp.lang.c++, comp.lang.c++.moderated
From "James K. Lowden" <jklowden@speakeasy.net>
Subject Re: C++ exceptions are broken.
Organization http://www.NewsDemon.com
References <wuCdnSxusZPATkDLnZ2dnUU7-VlQAAAA@giganews.com> <20160308184714.bdb1e8f73fd1db86e9c83dc9@speakeasy.net> <NN-dnVoIWp4b-XnLnZ2dnUU7-WVj4p2d@giganews.com>
Date 2016-03-13 15:55 -0600

Cross-posted to 2 groups.

Show all headers | View raw


On Sat, 12 Mar 2016 14:46:06 CST
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> wrote:

> > I also don't understand how it *could* happen, since the compiler
> > generates exception-handling instructions, and the language per se
> > doesn't define logic_error.
> 
> Typically when constructing an exception derived from
> std::logic_error a std::string object is created for the exception
> message which can cause std::bad_alloc (a std::runtime_error
> exception) to be thrown replacing the originally intended exception.

Oh, so you mean that the programmer may do something in handling the
exception to convert logic_error to runtime_error.  Sure.  

The programmer also has control over that.  If it's important to pass
logic_error up the stack unmolested, do not allocate any objects in the
handler, or wrap that logic in its own try block.  I've heard that in
some shops it's standard practice to use only static strings in
handlers to avoid the situation you describe.  

>From my point of view, if std::string triggers bad_alloc, you're hip
deep in alligators because your heap is corrupted.  Likely is the
logic_error is itself spurious, a knock-on effect of your pointers
spending their spring break in Fort Lauderdale.  So, yeah, grap
__FILE__ and __LINE__, and head for the exit as soon as possible.  

--jkl


-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

Back to comp.lang.c++ | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

C++ exceptions are broken. Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> - 2016-03-08 06:31 -0600
  Re: C++ exceptions are broken. woodbrian77@gmail.com - 2016-03-08 07:10 -0800
    Re: C++ exceptions are broken. scott@slp53.sl.home (Scott Lurndal) - 2016-03-08 17:26 +0000
  Re: C++ exceptions are broken. "James K. Lowden" <jklowden@speakeasy.net> - 2016-03-09 08:25 -0600
    Re: C++ exceptions are broken. Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> - 2016-03-12 19:11 +0000
      Re: C++ exceptions are broken. Öö Tiib <ootiib@hot.ee> - 2016-03-12 15:05 -0800
    Re: C++ exceptions are broken. Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> - 2016-03-12 14:46 -0600
      Re: C++ exceptions are broken. Hergen Lehmann <hlehmann.expires.5-11@snafu.de> - 2016-03-12 16:50 -0600
      Re: C++ exceptions are broken. "James K. Lowden" <jklowden@speakeasy.net> - 2016-03-13 15:55 -0600
        Re: C++ exceptions are broken. Gareth Owen <gwowen@googlemail.com> - 2016-03-15 08:45 -0600
          Re: C++ exceptions are broken. Bo Persson <bop@gmb.dk> - 2016-03-15 12:22 -0600
            Re: C++ exceptions are broken. woodbrian77@gmail.com - 2016-03-15 11:28 -0700
            Re: C++ exceptions are broken. "Alf P. Steinbach" <alf.p.steinbach+usenet@googlemail.com> - 2016-03-17 06:43 -0600
            Re: C++ exceptions are broken. Paavo Helde <myfirstname@osa.pri.ee> - 2016-03-17 06:43 -0600
      Re: C++ exceptions are broken. Gareth Owen <gwowen@googlemail.com> - 2016-03-15 08:44 -0600

csiph-web