Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #37776
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Two exceptions |
| Date | 2017-12-09 14:55 -0500 |
| Organization | A noiseless patient Spider |
| Message-ID | <p0hf3r$37q$1@dont-email.me> (permalink) |
| References | <p0f54o$n5f$1@gioia.aioe.org> <parsing-20171209171108@ram.dialup.fu-berlin.de> |
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> - 2017-12-09 00:53 +0200
Re: Two exceptions Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-12-08 18:21 -0500
Re: Two exceptions Victor Porton <porton@narod.ru> - 2017-12-09 01:55 +0200
Re: Two exceptions Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-12-09 07:39 -0500
Re: Two exceptions Victor Porton <porton@narod.ru> - 2017-12-10 02:39 +0200
Re: Two exceptions Victor Porton <porton@narod.ru> - 2017-12-10 02:46 +0200
Re: Two exceptions Kiwi User <martin@mydomain.invalid> - 2017-12-10 00:52 +0000
Re: Two exceptions Patrick Roemer <sangamon@netcologne.de> - 2017-12-09 13:47 +0100
Re: Two exceptions Arne Vajhøj <arne@vajhoej.dk> - 2017-12-08 18:49 -0500
Re: Two exceptions v_borchert@despammed.com (Volker Borchert) - 2017-12-09 07:53 +0000
Re: Two exceptions Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-12-09 14:55 -0500
Re: Two exceptions Patrick Roemer <sangamon@netcologne.de> - 2017-12-11 15:09 +0100
csiph-web