🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #3695

Re: Exception handling -- was a finally block ever considered?

#3695
From: Eric W. Biederman
Date: Sat, 16 Mar 1996 10:13
51 lines
2120 bytes
In article <31475017.8100207@nntp.ix.netcom.com> jdmorris@ix.netcom.com
(Jason D. Morris) writes:

   I would like to know if the following construct was ever considered by
   the C++ and if it was, why it was rejected.

   try
   {
       // some code that could generate an exception...
   }
   catch ( // some expected exception type )
   {
       // handler code
   }
   finally
   {
       // code that would be guaranteed to execute no matter how the 
       // function was exited.
   }

This can be written quite easily as I see it with C++, though the
structure is a little awkward. 

Basically you just need to write a destructor.  The code ordering is a
little less pleasant 
Say,

func( ... )
{
   class finally{
   public:
   ~finally()
   {
       // code that would be guaranteed to execute no matter how the 
       // function was exited.
   } finally;
   try
   {
       // some code that could generate an exception...
   }
   catch ( // some expected exception type )
   {
       // handler code
   }
}
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
Technical Details
Message-ID: <ERIC.96Mar15153848@cse.unl.edu>
Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back
References: <31475017.8100207@nntp.ix.netcom.com>

Show Full Headers
Complete Article Headers
From: ebiederm@cse.unl.edu (Eric W. Biederman)
Message-ID: <ERIC.96Mar15153848@cse.unl.edu>
X-Original-Date: 15 Mar 1996 21:38:48 GMT
Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back
Date: 16 Mar 96 10:13:46 GMT
Approved: fjh@cs.mu.oz.au
Newsgroups: comp.std.c++
Subject: Re: Exception handling -- was a finally block ever considered?
Organization: University of Nebraska--Lincoln 
References: <31475017.8100207@nntp.ix.netcom.com>
In-Reply-To: jdmorris@ix.netcom.com's message of 13 Mar 96 23:50:08 GMT
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBFAgUBMUqUZ+EDnX0m9pzZAQHHCwF/WbETwMaD5RbtsuQm4NRdlxK3L9fOGY/P
 E4DAJg0WRVNwI2OqQVwe/jRDP7FIBFRg
 =ODJ4