This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: How would you write a finally clause in C++?
- To: Erwin Bolwidt <ejb at klomp dot org>
- Subject: Re: How would you write a finally clause in C++?
- From: Tom Tromey <tromey at redhat dot com>
- Date: 27 May 2001 13:40:18 -0600
- Cc: <java at gcc dot gnu dot org>
- References: <Pine.LNX.4.33.0105272046470.5985-100000@galileo.zap.tm>
- Reply-To: tromey at redhat dot com
>>>>> "Erwin" == Erwin Bolwidt <ejb@klomp.org> writes:
Erwin> I hope this is the right list to ask. When you want to write a
Erwin> try {} finally {} clause in C++ in a CNI method, how would you
Erwin> do that?
It might not be the right list. General C++ questions should be
referred elsewhere, probably one of the C++ newsgroups.
Erwin> I've searched through the source of gcc/java and gcc/expr.c,
Erwin> and I found support for TRY_FINALLY in the compiler support
Erwin> file gcc/expr.c; so it should be accessible for the C++
Erwin> compiler, right?
No, not necessarily. Trees have to support the union of all the
languages supported by gcc. That doesn't mean that all supported
languages can generate all supported tree types.
Erwin> So how would you write a CNI method that does the same as this
Erwin> Java method:
Erwin> void method()
Erwin> {
Erwin> Writer w = new FileWriter(FILE);
Erwin> try {
Erwin> w.write("something".toCharArray());
Erwin> }
Erwin> finally {
Erwin> w.close();
Erwin> }
Erwin> }
One approach would be to introduce a new class and put the cleanup
code in the destructor.
Tom