Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Gene Wirchenko Newsgroups: comp.lang.java.programmer Subject: Re: Call by Result Date: Fri, 10 Jun 2011 11:59:20 -0700 Organization: A noiseless patient Spider Lines: 33 Message-ID: References: <4df23fe3$0$12157$fa0fcedb@news.zen.co.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Injection-Info: mx04.eternal-september.org; posting-host="7Qrvczazr82YckO5XW8Vtw"; logging-data="18868"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/PBkJoH9MKWzcBPJESsGucDw+8VP+BR8Y=" X-Newsreader: Forte Agent 4.2/32.1118 Cancel-Lock: sha1:/lN0YoUN2E5uxxZxIBOdtGDzncg= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:5200 On Fri, 10 Jun 2011 17:01:36 +0100, RedGrittyBrick wrote: >On 10/06/2011 07:03, Gene Wirchenko wrote: [snip] >> I am writing a simple preprocessor. I have a few spots where a >> string needs to be parsed. I want to call something like this: >> String ReturnString=""; >> boolean DidItWork=GetString(ReturnString); >> if (!DidItWork) >> // too bad >> It is not acceptable to have a special String value mean failure. I >> want the method to be able to return any potential string. >I think Stephan Ram's answer is roughly what I would do. > >String returnString; >Thagomizor thangomizor = new Thagomizor(); >thangomizor.thangomize(); >if (!thangomizor.didItWork()) { > throw new TooBadException(); >} else { > returnString = thangomizor.getString(); >} Lengthy code (compared with what it could be) to no additional benefit. Sincerely, Gene Wirchenko