Topic: Exception handling -- was a finally block e
Author: chase@centerline.com (David Chase)
Date: 1996/03/14 Raw View
In article 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
> { }
> catch ( // some expected exception type )
> {}
> finally
> {
> // code that would be guaranteed to execute no matter how the
> // function was exited.
> }
>
> Basically, a Java style finally clause. I also found it interesting
> that Microsoft's structured exception handling under Win32 includes a
> finally clause.
Why, I'm not sure. One possibility might be that it was judged to be
not necessary, because you can get the same effect in other ways.
You can get the same effect if you wrap the try-catch up in a block that
contains a local variable with an object type that does what you need.
As in:
{
class fin {
public:
~fin() {
...
}
fin( parameters ) {
...
}
};
fin finally(parameters);
try {} catch {}
} // finally's destructor will be run here.
This is not going to win any beauty contests, of course, but what
did you expect?
speaking for myself,
David Chase
---
[ 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 ]