Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #37783
| From | Patrick Roemer <sangamon@netcologne.de> (Patrick Roemer) |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Two exceptions |
| Date | 2017-12-09 13:47 +1200 |
| Organization | fsxNet Usenet Gateway | bbs.geek.nz/#fsxNet |
| Message-ID | <2326571928@f38.n261.z1.binkp.net> (permalink) |
| References | <1735587349@f38.n261.z1.binkp.net> |
Responding to Victor Porton: > The main reason I chose to use exceptions for this, is to allow parse() > method to return the result of parsing (not a boolean value). For example > result of parsing an integer may return "long". > > Can you propose another alternative? It is to be easily programmable (if I > find handling exceptions too slow, I always can rewrite my program). > > Oh, I see, you proposed to return "null" instead of my ParseException. It > however also seems to me not a quite good solution, because returning null > may be a non-exceptionable situation (as for a missing optional object in > the parsed resource). Instead of null, you could use (potentially nested) java.util.Optional for both, signaling failed parse attempts and optional productions. failure: empty success (plain): of(x) success (optional, non-match): of(empty) success (optional, match): of(of(x)) Preferably, you could introduce a specialized union type for the parse result, allowing you to propagate detail information in the failure case. See the Reply type here, for example: https://github.com/jon-hanson/parsecj#types Best regards, Patrick
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