Thread View: comp.std.c++
5 messages
5 total messages
Started by Jason D. Morris
Wed, 13 Mar 1996 23:50
Exception handling -- was a finally block ever considered?
Author: Jason D. Morris
Date: Wed, 13 Mar 1996 23:50
Date: Wed, 13 Mar 1996 23:50
28 lines
1530 bytes
1530 bytes
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.
}
Basically, a Java style finally clause. I also found it interesting
that Microsoft's structured exception handling under Win32 includes a
finally clause.
Jason
---
[ 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 ]
Re: Exception handling -- was a finally block e
Author: David Chase
Date: Thu, 14 Mar 1996 16:47
Date: Thu, 14 Mar 1996 16:47
54 lines
2209 bytes
2209 bytes
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 ]
Re: Exception handling -- was a finally block ever considered?
Author: Eric W. Biederman
Date: Sat, 16 Mar 1996 10:13
Date: Sat, 16 Mar 1996 10:13
51 lines
2120 bytes
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 ]
Re: Exception handling -- was a finally block ever considered?
Author: Jason D. Morris
Date: Sun, 17 Mar 1996 03:57
Date: Sun, 17 Mar 1996 03:57
40 lines
2000 bytes
2000 bytes
On 16 Mar 96 10:13:46 GMT, ebiederm@cse.unl.edu (Eric W. Biederman)
wrote:
>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
> }
>}
Ok, but that still doesn't answer my question. I didn't ask for a
method for simulating a finally block, I asked if the committee had
considered a finally block as part of the exception handling
mechanism, and if they had, why it wasn't adopted.
Jason
---
[ 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 ]
Re: Exception handling -- was a finally block ever considered?
Author: Fredrik Jonsson
Date: Thu, 21 Mar 1996 16:28
Date: Thu, 21 Mar 1996 16:28
26 lines
1932 bytes
1932 bytes
Jason D. Morris wrote: > > Ok, but that still doesn't answer my question. I didn't ask for a > method for simulating a finally block, I asked if the committee had > considered a finally block as part of the exception handling > mechanism, and if they had, why it wasn't adopted. > > Jason I know the finally statement was mentioned/discussed during afterwork hours at the Santa Cruz meeting but unfortunately that is about it. (I agree with you that it is very convenient to have the finally block, and most Borland Delphi or Java programmers will agree on that.) Ie. the answer to your question would be no, it has not been discussed, at least not as far as I know. /F. Jonsson [ 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 ]
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads