Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #37776

Re: Two exceptions

Path csiph.com!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From Eric Sosman <esosman@comcast-dot-net.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: Two exceptions
Date Sat, 9 Dec 2017 14:55:38 -0500
Organization A noiseless patient Spider
Lines 46
Message-ID <p0hf3r$37q$1@dont-email.me> (permalink)
References <p0f54o$n5f$1@gioia.aioe.org> <parsing-20171209171108@ram.dialup.fu-berlin.de>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 7bit
Injection-Date Sat, 9 Dec 2017 19:55:39 -0000 (UTC)
Injection-Info reader02.eternal-september.org; posting-host="c74a59556596067f66f4bbd6694370b5"; logging-data="3322"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18S+MwE6TysgV3TapN1BnwR"
User-Agent Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0
In-Reply-To <parsing-20171209171108@ram.dialup.fu-berlin.de>
Content-Language en-US
Cancel-Lock sha1:blNytgnogyLdzVdmx7EQEwt1S5Y=
Xref csiph.com comp.lang.java.programmer:37776

Show key headers only | View raw


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


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