Path: csiph.com!aioe.org!.POSTED!not-for-mail From: Victor Porton Newsgroups: comp.lang.java.programmer Subject: Two exceptions Date: Sat, 09 Dec 2017 00:53:13 +0200 Organization: Aioe.org NNTP Server Lines: 41 Message-ID: NNTP-Posting-Host: Sz6TxwyziwPWhj5bu0SdBw.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Complaints-To: abuse@aioe.org User-Agent: KNode/4.14.10 X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com comp.lang.java.programmer:37737 I am writing something like a recursive descent parser: That is, I inspect object and its parts. When a part of an object is wrong, my method parse() throws my exception ParseException. It is sometimes handled in parse() of a higher-level object. Example: An object X may be either X1 or X2 or X3 class. I try to call parse() for an object of X1 class. If it parses, the higher level parse() (for X) return X1 casted to X. If it fails with exception ParseException, X2 is tried, and if that fails too X3 is tried. Or for an object X I try calling parse() for subobjects Y and Z. If either throws ParseException, the parse exception is propagated for parse() of X. In this way, I consider an object and its possible parts. This is sometimes called recursive descent. But I want also FatalParseException meant to stop parsing of a file altogether if it happens in the object or its subobject. Human logic suggests that FatalParseException is a kind of ParseException and so should be its subclass. But this way handling ParseException we would also handle FatalParseException what is wrong, because FatalParseException is meant to be handled only in the outer method, outside of all parse() methods. So I have two alternatives: 1. Derive ParseException from FatalParseException what seems to do the right thing but seems illogical. 2. Not derive either of these two exceptions from each other. By the way, I am to rewrite an Ada project in Java (because the Ada compiler is too buggy and I can't work with it). In Ada all exceptions are independent (no exception is a subclass of another one). -- Victor Porton - http://portonvictor.org