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


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

Re: need argument for try catch blocks

From Edek <edek.pieITAKNIECZYTAM@gmail.com>
Newsgroups comp.lang.c++
Subject Re: need argument for try catch blocks
Date 2011-05-27 15:54 +0200
Organization ATMAN - ATM S.A.
Message-ID <iroa4t$3io$1@node2.news.atman.pl> (permalink)
References <b5983f42-b483-48da-bd66-21d4cecd88b1@v31g2000vbs.googlegroups.com> <iro3o6$t1o$1@node2.news.atman.pl> <iro4ma$f08$1@news.ett.com.ua> <iro694$vgm$1@node2.news.atman.pl> <iro7so$gfb$1@news.ett.com.ua>

Show all headers | View raw


On 05/27/2011 03:10 PM, Balog Pal wrote:
> "Edek" <edek.pieITAKNIECZYTAM@gmail.com>
>
>> Is it possible to do anything which may throw during stack unwind? I
>> always thought that was UB.
>
> Depends. If you use the standard library, it states that you'll have UB
> if your type T emits an exception from a destructor.
>
> In general that is not UB, but a double exception will end up in
> terminate(). And a throwing destructor can leave behind memory leaks,
> incosistencies and much other stuff you do not want. for that reason it
> is a strong guideline that destructors must be nothrow. Those ignoring
> it are likely in peril regardless other stuff.

Yes, that I know. Actually, what I mean is this

struct Deleter {
     ... holds a DB connection

     ~Deleter () {
         try {
	   .. whatever that may throw
         } catch (...) {} // does not emit. But is it legal?	
}

int some {
      scoped_ptr<Deleter> del(new Deleter(openDbConnection()) );

      // ... here something throws
      // destructor throws and catches
      // is this UB?
}

Is this UB or not? I've always thought it is.

>
>>>> c) to log, if there are no stack traces and for some reason a debugger
>>>> cannot be used, or just it is quicker to have a log without plugging
>>>> in a debugger
>>>
>>> Logging is a suspicious reason, and if really needed also can be done
>>> better in a RAII-like form. Though special cases may apply.
>>
>> Like having no exception stack trace? Hell, I like getting at the top
>> of the thread an information along the lines of 'Integer conversion
>> failed' and nothing more.
>
> If you write correct software, you will not have that. If it is caused
> by not software but input external input, then you can dump the input at
> that place, and figure out why it was not fit for purpose.

Ok, integer conversion is just an example, could be anything.

>
> As I told before, chasing more log and traci is a usual activity that
> correlates tith WTF-ish codebase. The rrot fix of that is not adding
> more trace support but start work on reviews and fixes.
>
> Whily really hairy environments support externally controllable trace.
> Like the linux kernel -- you can echo > to turn on tracepoints, debug
> messages on a single module, or even on a single line of source if
> interested. And it is NOT there for the regular case. Neither needs
> excess code for tracing (only for special messages).

Yes, like entering an important function pushes something on TLS log 
context, or whatever via RAII. I know. Somewhere in this thread there 
was something said about hard debugging.

>
> And adding noise to the code provably hinders making it right. While
> making it simpler and easier to read leads to less problems to look
> after. Or putting the same effort into unit tests will more likely find
> the cause of your integer conversion.
>

Sure, there is a fake tradeoff between quality and effort. Quality here 
would mean that there is no need (or place) for weird stuff, and 
debugging would be easy. That's when a project has a reasonable policy, 
in this case of error handling, even in the midst of various libraries. 
The tradeoff works in the short run, in the long run is a pain, I'm not 
sure about the overrated TCD ;) (Total Cost of Development).

But this is more about the project in large. I do prefer raii, but it 
needs consistency.

Edek

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


Thread

need argument for try catch blocks Christopher <cpisz@austin.rr.com> - 2011-05-26 08:20 -0700
  Re: need argument for try catch blocks "Balog Pal" <pasa@lib.hu> - 2011-05-26 18:24 +0200
    Re: need argument for try catch blocks Christopher <cpisz@austin.rr.com> - 2011-05-26 10:28 -0700
      Re: need argument for try catch blocks Christopher <cpisz@austin.rr.com> - 2011-05-26 10:31 -0700
      Re: need argument for try catch blocks "Balog Pal" <pasa@lib.hu> - 2011-05-26 20:36 +0200
        Re: need argument for try catch blocks Keith H Duggar <duggar@alum.mit.edu> - 2011-05-27 06:10 -0700
  Re: need argument for try catch blocks Juha Nieminen <nospam@thanks.invalid> - 2011-05-27 06:40 +0000
  Re: need argument for try catch blocks Edek <edek.pieITAKNIECZYTAM@gmail.com> - 2011-05-27 14:05 +0200
    Re: need argument for try catch blocks "Balog Pal" <pasa@lib.hu> - 2011-05-27 14:16 +0200
      Re: need argument for try catch blocks Edek <edek.pieITAKNIECZYTAM@gmail.com> - 2011-05-27 14:48 +0200
        Re: need argument for try catch blocks "Balog Pal" <pasa@lib.hu> - 2011-05-27 15:10 +0200
          Re: need argument for try catch blocks Edek <edek.pieITAKNIECZYTAM@gmail.com> - 2011-05-27 15:54 +0200
            Re: need argument for try catch blocks "Balog Pal" <pasa@lib.hu> - 2011-05-27 16:13 +0200
          Re: need argument for try catch blocks "Fred Zwarts" <F.Zwarts@KVI.nl> - 2011-05-30 09:56 +0200
            Re: need argument for try catch blocks "Balog Pal" <pasa@lib.hu> - 2011-05-30 10:22 +0200
      Re: need argument for try catch blocks Christopher <cpisz@austin.rr.com> - 2011-05-27 07:43 -0700
        Re: need argument for try catch blocks Paavo Helde <myfirstname@osa.pri.ee> - 2011-05-27 10:19 -0500
        Re: need argument for try catch blocks "Balog Pal" <pasa@lib.hu> - 2011-05-27 17:58 +0200
          Re: need argument for try catch blocks Keith H Duggar <duggar@alum.mit.edu> - 2011-05-30 09:43 -0700
            Re: need argument for try catch blocks Öö Tiib <ootiib@hot.ee> - 2011-05-30 11:58 -0700
            Re: need argument for try catch blocks Christopher <cpisz@austin.rr.com> - 2011-05-31 08:57 -0700
              Re: need argument for try catch blocks Keith H Duggar <duggar@alum.mit.edu> - 2011-05-31 13:33 -0700
                Re: need argument for try catch blocks Ian Collins <ian-news@hotmail.com> - 2011-06-01 09:03 +1200
                Re: need argument for try catch blocks Keith H Duggar <duggar@alum.mit.edu> - 2011-05-31 14:57 -0700
                Re: need argument for try catch blocks "Balog Pal" <pasa@lib.hu> - 2011-06-01 02:06 +0200
                Re: need argument for try catch blocks Öö Tiib <ootiib@hot.ee> - 2011-05-31 16:32 -0700
                Re: need argument for try catch blocks Christopher <cpisz@austin.rr.com> - 2011-06-01 11:42 -0700
                Re: need argument for try catch blocks Keith H Duggar <duggar@alum.mit.edu> - 2011-06-02 16:01 -0700
                Re: need argument for try catch blocks Öö Tiib <ootiib@hot.ee> - 2011-06-03 04:27 -0700
                Re: need argument for try catch blocks Christopher <cpisz@austin.rr.com> - 2011-06-03 07:39 -0700
                Re: need argument for try catch blocks Öö Tiib <ootiib@hot.ee> - 2011-06-03 10:43 -0700
                Re: need argument for try catch blocks Keith H Duggar <duggar@alum.mit.edu> - 2011-06-03 11:31 -0700
                Re: need argument for try catch blocks Christopher <cpisz@austin.rr.com> - 2011-06-03 12:14 -0700
                Re: need argument for try catch blocks Leigh Johnston <leigh@i42.co.uk> - 2011-06-03 21:22 +0100
                Re: need argument for try catch blocks Edek <edek.pienkowski@gmail.com> - 2011-06-03 21:17 +0200
                Re: need argument for try catch blocks Joshua Maurice <joshuamaurice@gmail.com> - 2011-06-03 18:24 -0700
                Re: need argument for try catch blocks Christopher <cpisz@austin.rr.com> - 2011-06-03 07:51 -0700
                Re: need argument for try catch blocks "Alf P. Steinbach /Usenet" <alf.p.steinbach+usenet@gmail.com> - 2011-06-03 20:57 +0200
        Re: need argument for try catch blocks Edek <edek.pieITAKNIECZYTAM@gmail.com> - 2011-05-27 19:01 +0200
          Re: need argument for try catch blocks Öö Tiib <ootiib@hot.ee> - 2011-05-31 17:13 -0700
            Re: need argument for try catch blocks Edek <edek.pienkowski@gmail.com> - 2011-06-03 16:04 +0200
              Re: need argument for try catch blocks Öö Tiib <ootiib@hot.ee> - 2011-06-03 09:44 -0700
                Re: need argument for try catch blocks Edek <edek.pienkowski@gmail.com> - 2011-06-03 19:04 +0200

csiph-web