Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #32930
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Martin Gregorie <martin@address-in-sig.invalid> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Way to avoid repeating to catch the same exception in overridden method |
| Date | Fri, 23 Oct 2015 10:32:53 +0000 (UTC) |
| Organization | A noiseless patient Spider |
| Lines | 35 |
| Message-ID | <n0d2cl$k3f$1@dont-email.me> (permalink) |
| References | <fd943245-c84e-4b93-9ed5-e18fb25e256a@googlegroups.com> <5629f731$0$23869$e4fe514c@news.xs4all.nl> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | 8bit |
| Injection-Date | Fri, 23 Oct 2015 10:32:53 +0000 (UTC) |
| Injection-Info | mx02.eternal-september.org; posting-host="e5160e2be48f1ea550cf61512446f525"; logging-data="20591"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/3k5lX0K1t0mGsuQSJ38d2+Z2y7oRRpKM=" |
| User-Agent | Pan/0.139 (Sexual Chocolate; GIT bf56508 git://git.gnome.org/pan2) |
| Cancel-Lock | sha1:ohQu7AQQe5daeWQcFtI4bw7IQBs= |
| Xref | csiph.com comp.lang.java.programmer:32930 |
Show key headers only | View raw
On Fri, 23 Oct 2015 11:00:33 +0200, Silvio wrote: > As others already stated something is fishy if getXXX() without > parameters can throw an exception unless you have defined that getting > XXX when the object does not have an XXX at all is invalid. But in that > case there should also be something to query that, say a hasXXX() or > something similar. Returning null to indicate a missing value might > simply work here as well. > > I think it is a bad idea to try to hide the exception from the user by > filling in empty values. The result will be wrong anyway but neither the > user nor yourself will be alerted. > > At the very least replace the COMPLETE toString result with a value that > indicates that something is wrong and show that to the user. Also a lot > simpler to code. > > But by all means consider throwing the exception if it actually > indicates a program error. If it doesn't then consider not throwing the > exception in the first place. > > +1 Returning null is common in both C and Java under these circumstances and is simple enough to check for. All you need to is to update the method- level comment to say that null can be returned and describe the circumstances when this can occur (your project DOES mandate the use javadocs, doesn't it?). -- martin@ | Martin Gregorie gregorie. | Essex, UK org |
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar | Unroll thread
Way to avoid repeating to catch the same exception in overridden method mike <mikaelpetterson@hotmail.com> - 2015-10-19 01:02 -0700
Re: Way to avoid repeating to catch the same exception in overridden method Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-10-19 12:11 -0400
Re: Way to avoid repeating to catch the same exception in overridden method Robert Klemme <shortcutter@googlemail.com> - 2015-10-23 08:59 +0200
Re: Way to avoid repeating to catch the same exception in overridden method Martin Gregorie <martin@address-in-sig.invalid> - 2015-10-19 12:26 +0000
Re: Way to avoid repeating to catch the same exception in overridden method Silvio <silvio@internet.com> - 2015-10-23 11:00 +0200
Re: Way to avoid repeating to catch the same exception in overridden method Martin Gregorie <martin@address-in-sig.invalid> - 2015-10-23 10:32 +0000
csiph-web