Path: csiph.com!news.bbs.geek.nz!.POSTED.agency.bbs.geek.nz!not-for-mail From: ram@zedat.fu-berlin.de (Stefan Ram) (Stefan Ram) Newsgroups: comp.lang.java.programmer Subject: Re: Two exceptions Date: Sat, 09 Dec 2017 16:15:06 +1200 Organization: fsxNet Usenet Gateway | bbs.geek.nz/#fsxNet Message-ID: <3577663232@f38.n261.z1.binkp.net> References: <4199194256@f38.n261.z1.binkp.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Injection-Info: news.bbs.geek.nz; posting-host="M6YmRdZYyc42DJk0lNlt/X4dpP4dzvceBNabSmESN3E"; logging-data="10956"; mail-complaints-to="abuse@news.bbs.geek.nz" User-Agent: VSoup v1.2.9.47Beta [95/NT] X-MailConverter: SoupGate-Win32 v1.05 X-Comment-To: Victor Porton Xref: csiph.com comp.lang.java.programmer:37784 Victor Porton 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). But without knowing more details of the problem, it is difficult to suggest further details. >An object X may be either X1 or X2 or X3 class. When X is not X1, of course, this is neither an error nor a reason to throw. (Check whether you might use the anti-pattern "switch on (sub)type [i.e., X1, X2, X3]" whose use should be replaced by polymorphism.) Traversing given nested objects is not called "parsing" (which is working on a sequence of tokens), it is more like a tree travesal, which might suggest to check out the visitor pattern.