Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #37793
| From | Eric Sosman <esosman@comcast-dot-net.invalid> (Eric Sosman) |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Two exceptions |
| Date | 2017-12-09 14:55 +1200 |
| Organization | fsxNet Usenet Gateway | bbs.geek.nz/#fsxNet |
| Message-ID | <168218953@f38.n261.z1.binkp.net> (permalink) |
| References | <3577663232@f38.n261.z1.binkp.net> |
On 12/9/2017 11:15 AM, Stefan Ram wrote:
> Victor Porton <porton@narod.ru> writes:
>> So I have two alternatives:
>> 1. Derive ParseException from FatalParseException what seems to do the right
>> thing but seems illogical.
>
> The type of a result of a parse is
>
> class ParseResult { ...
>
> which can have subclasses
>
> class ProperParseResult extends ParseResult { ...
> class ErrorParseResult extends ParseResult { ...
>
> which in turn can have several subclasses each of which
> might implement several interfaces.
>
> A parseResult might contain other parseResults (AST).
This would work, yes, but I think it would lead to clumsy
code at the call site, something like
ParseResult result = parse();
if (result instanceof ProperParseResult) {
ProperParseResult ppr = (ProperParseResult) result;
...
} else if (result instanceof ErrorParseResult) {
ErrorParseResult epr = (ErrorParseResult) result;
...
} else {
throw new IllegalStateException("bad result", result);
}
That is, you'd need to use `instanceof' (or equivalent) to learn what kind of a
result you obtained -- and if you find yourself using `instanceof' a lot,
that's usually a sign that the design could be improved.
(It can be argued that `try/catch' is a disguised `instanceof',
particularly if there are multiple `catch' clauses. This seems forgivable,
though, on the grounds that exceptions are "unusual.")
--
esosman@comcast-dot-net.invalid
Eleven hundred thirty-eight days to go.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Two exceptions Victor Porton <porton@narod.ru> (Victor Porton) - 2017-12-09 00:53 +1200
Re: Two exceptions Eric Sosman <esosman@comcast-dot-net.invalid> (Eric Sosman) - 2017-12-08 18:21 +1200
Re: Two exceptions Victor Porton <porton@narod.ru> (Victor Porton) - 2017-12-09 01:55 +1200
Re: Two exceptions Eric Sosman <esosman@comcast-dot-net.invalid> (Eric Sosman) - 2017-12-09 07:39 +1200
Re: Two exceptions Victor Porton <porton@narod.ru> (Victor Porton) - 2017-12-10 02:39 +1200
Re: Two exceptions Victor Porton <porton@narod.ru> (Victor Porton) - 2017-12-10 02:46 +1200
Re: Two exceptions Kiwi User <martin@mydomain.invalid> (Kiwi User) - 2017-12-10 00:52 +1200
Re: Two exceptions Kiwi User <martin@mydomain.invalid> - 2017-12-10 21:50 +0000
Re: Two exceptions Patrick Roemer <sangamon@netcologne.de> (Patrick Roemer) - 2017-12-09 13:47 +1200
Re: Two exceptions Arne Vajhøj <arne@vajhoej.dk> (Arne Vajhøj) - 2017-12-08 18:49 +1200
Re: Two exceptions v_borchert@despammed.com (Volker Borchert) (Volker Borchert) - 2017-12-09 07:53 +1200
Re: Two exceptions ram@zedat.fu-berlin.de (Stefan Ram) (Stefan Ram) - 2017-12-09 16:15 +1200
Re: Two exceptions Eric Sosman <esosman@comcast-dot-net.invalid> (Eric Sosman) - 2017-12-09 14:55 +1200
Re: Two exceptions Patrick Roemer <sangamon@netcologne.de> (Patrick Roemer) - 2017-12-11 15:09 +1200
Re: Two exceptions Victor Porton <porton@narod.ru> - 2017-12-12 11:14 +0200
csiph-web