Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.c++.moderated    |    Moderated discussion of C++ superhackery    |    33,346 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 32,390 of 33,346    |
|    Dave Harris to Edward Rosten    |
|    Re: Will we ever be able to throw from a    |
|    08 Jun 12 18:24:26    |
   
   9a6942c3   
   From: brangdon@cix.compulink.co.uk   
      
   edward.rosten@gmail.com (Edward Rosten) wrote (abridged):   
   > Without making it possible to have exceptions in the dtor, one has   
   > to write repetitive code on every file usage to manually call close   
   > before destructing the file in order to get proper error reporting,   
   > which isn't something that needs to be done with other file related   
   > calls.   
   >   
   > To me, if you have to write repetitive code, then the language is   
   > missing some expressiveness.   
      
   It may just be that you need some other language feature. For   
   example, we could design some class File to support:   
      
    void process( const char *filename ) {   
    File::with( filename, "w", []( File &file ) {   
    // ... write to the open file.   
    } );   
    }   
      
   In normal flow, File::with() opens the file, passes it to the   
   lambda, then flushes it and closes it. If the lambda throws, the   
   file is merely closed and deleted. The first error is preserved and eventually   
   rethrown; subsequent ones are ignored.   
      
   Or whatever. The point is that the implementation can do whatever   
   you think is best, and use whatever combination of destructors and   
   try/catch, and be as messy as it needs to be, and it doesn't matter   
   because it's all encapsulated nicely by File.   
      
   Lambda expressions are a great tool for separation of concerns. I   
   keep them close to the top of my toolbox.   
      
   -- Dave Harris, Nottingham, UK.   
      
      
   --   
    [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
    [ comp.lang.c++.moderated. First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca