Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #26257
| Path | csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Jim Janney <jjanney@shell.xmission.com> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: unnecessary code in Oracle example? |
| Date | Wed, 09 Oct 2013 13:08:57 -0600 |
| Organization | a plan in my flaw |
| Lines | 38 |
| Message-ID | <ydneh7ujm7q.fsf@shell.xmission.com> (permalink) |
| References | <ydnr4bujt72.fsf@shell.xmission.com> <u6h5u.69447$yx6.64233@fx26.iad> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| Injection-Info | mx05.eternal-september.org; posting-host="c75a2e3068ccf6c98395286f3e40b97d"; logging-data="11729"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18fDnPRei1jg0f5oQURDRFh" |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) |
| Cancel-Lock | sha1:b05LQhIV7AsvZo0+BseSwAoZpOI= sha1:bwZG4QWbHo3ShkEu8Q7l5+HSpak= |
| Xref | csiph.com comp.lang.java.programmer:26257 |
Show key headers only | View raw
Daniel Pitts <newsgroup.nospam@virtualinfinity.net> writes:
> You are correct for this case, the other case comes from a block which
> uses multiple resources.
>
> MyResource r1 = null;
> MyResource r2 = null;
>
> try {
> r1 = openResource1();
> r2 = openResource2();
> } finally {
> if (r1 != null) r1.close();
> if (r2 != null) r2.close();
> }
>
> Of course, some close() methods can throw, which could break this
> idiom too. This is one reason why C++ forbids destructors from
> throwing.
Thanks. But that looks like a good idiom to avoid. I prefer
MyResource r1 = openResource();
try {
MyResource r2 = openResource2();
try {
// do something
} finally {
r2.close();
}
} finally {
r1.close();
}
Not as pretty syntactically, perhaps, but much clearer semantically.
--
Jim Janney
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
unnecessary code in Oracle example? Jim Janney <jjanney@shell.xmission.com> - 2013-10-09 10:38 -0600
Re: unnecessary code in Oracle example? Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2013-10-09 11:19 -0700
Re: unnecessary code in Oracle example? ram@zedat.fu-berlin.de (Stefan Ram) - 2013-10-09 19:04 +0000
Re: unnecessary code in Oracle example? Jim Janney <jjanney@shell.xmission.com> - 2013-10-09 13:08 -0600
Re: unnecessary code in Oracle example? markspace <markspace@nospam.nospam> - 2013-10-09 12:27 -0700
Re: unnecessary code in Oracle example? Jim Janney <jjanney@shell.xmission.com> - 2013-10-09 14:21 -0600
Re: unnecessary code in Oracle example? markspace <markspace@nospam.nospam> - 2013-10-09 14:56 -0700
Re: unnecessary code in Oracle example? Jim Janney <jjanney@shell.xmission.com> - 2013-10-09 20:56 -0600
Re: unnecessary code in Oracle example? Arivald <NOSPAMarivald@interia.pl> - 2013-10-10 06:42 +0200
Re: unnecessary code in Oracle example? Sebastian <news@seyweiler.dyndns.org> - 2013-10-10 07:47 +0200
Re: unnecessary code in Oracle example? Arivald <arivald_@AT_interia_DOT_.pl> - 2013-10-10 10:26 +0200
Re: unnecessary code in Oracle example? Jim Janney <jjanney@shell.xmission.com> - 2013-10-10 08:47 -0600
Re: unnecessary code in Oracle example? Robert Klemme <shortcutter@googlemail.com> - 2013-10-09 21:11 +0200
Re: unnecessary code in Oracle example? cuzdav@gmail.com - 2013-10-10 08:49 -0700
csiph-web