Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #37219
| Newsgroups | comp.lang.java.programmer |
|---|---|
| Date | 2017-08-14 05:11 -0700 |
| References | <87zib6zeup.fsf@munus.decebal.nl> <omlidd$k9h$1@gioia.aioe.org> |
| Message-ID | <71a5a534-d065-410c-bda3-7e23067f76cb@googlegroups.com> (permalink) |
| Subject | Re: Where to put the return |
| From | Eric Douglas <e.d.programmer@gmail.com> |
On Friday, August 11, 2017 at 8:34:07 PM UTC-4, Arne Vajhøj wrote:
> I would go for:
>
> private static final String NO_VALUE = "";
> private static String getOldestUsed() {
> try (Statement stmt = sqlite3Conn.createStatement();
> ResultSet rsOldest = stmt.executeQuery(OLDEST_USED)) {
> if (rsOldest.next()) {
> return rsOldest.getString("used");
> } else {
> return NO_VALUE;
> }
> } catch (SQLException e) {
> giveError("Error in displayOldestUsed");
> e.printStackTrace();
> fatalError("");
> return NO_VALUE;
> }
> }
>
> But there are many acceptable ways of writing this.
>
> Arne
I'm not sure what exceptions you're trying to catch here. As Robert said it's most likely best to do something different with the catch clause, whether you simply throw the exception, or if for some reason it's not allowed to crash just return ERROR_VALUE;
I think Eclipse has a warning that says your else is irrelevant. You can always leave that verb out if the condition ends with a return.
ResultSet rsOldest = stmt.executeQuery(OLDEST_USED)) {
if (rsOldest.next()) {
return rsOldest.getString("used");
}
return NO_VALUE;
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Where to put the return Cecil Westerhof <Cecil@decebal.nl> - 2017-08-11 10:30 +0200
Re: Where to put the return Cecil Westerhof <Cecil@decebal.nl> - 2017-08-11 12:24 +0200
Re: Where to put the return Eric Douglas <e.d.programmer@gmail.com> - 2017-08-11 08:31 -0700
Re: Where to put the return Arne Vajhøj <arne@vajhoej.dk> - 2017-08-11 20:33 -0400
Re: Where to put the return Robert Klemme <shortcutter@googlemail.com> - 2017-08-13 00:27 +0200
Re: Where to put the return Arne Vajhøj <arne@vajhoej.dk> - 2017-08-12 21:41 -0400
Re: Where to put the return Robert Klemme <shortcutter@googlemail.com> - 2017-08-13 13:15 +0200
Re: Where to put the return Cecil Westerhof <Cecil@decebal.nl> - 2017-08-15 08:12 +0200
Re: Where to put the return Robert Klemme <shortcutter@googlemail.com> - 2017-08-19 11:10 +0200
Re: Where to put the return Cecil Westerhof <Cecil@decebal.nl> - 2017-08-19 12:54 +0200
Re: Where to put the return Cecil Westerhof <Cecil@decebal.nl> - 2017-08-19 13:46 +0200
Re: Where to put the return Cecil Westerhof <Cecil@decebal.nl> - 2017-08-19 14:10 +0200
Re: Where to put the return Robert Klemme <shortcutter@googlemail.com> - 2017-08-19 15:35 +0200
Re: Where to put the return Arne Vajhøj <arne@vajhoej.dk> - 2017-08-19 09:48 -0400
Re: Where to put the return Robert Klemme <shortcutter@googlemail.com> - 2017-08-19 23:26 +0200
Re: Where to put the return Arne Vajhøj <arne@vajhoej.dk> - 2017-08-19 20:01 -0400
Re: Where to put the return Robert Klemme <shortcutter@googlemail.com> - 2017-08-20 19:30 +0200
Re: Where to put the return Cecil Westerhof <Cecil@decebal.nl> - 2017-08-19 17:06 +0200
Re: Where to put the return Robert Klemme <shortcutter@googlemail.com> - 2017-08-19 15:35 +0200
Re: Where to put the return Arne Vajhøj <arne@vajhoej.dk> - 2017-08-19 09:43 -0400
Re: Where to put the return Cecil Westerhof <Cecil@decebal.nl> - 2017-08-19 17:15 +0200
Re: Where to put the return Robert Klemme <shortcutter@googlemail.com> - 2017-08-21 22:33 +0200
Re: Where to put the return lewbloch@gmail.com - 2017-08-19 09:20 -0700
Re: Where to put the return Robert Klemme <shortcutter@googlemail.com> - 2017-08-21 22:29 +0200
Re: Where to put the return Eric Douglas <e.d.programmer@gmail.com> - 2017-08-14 05:11 -0700
Re: Where to put the return Brixomatic <brixomatic@yahoo.com> - 2017-08-31 19:27 +0200
csiph-web