Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.dougwise.org!nntpfeed.proxad.net!proxad.net!feeder1-1.proxad.net!198.186.194.247.MISMATCH!news-out.readnews.com!transit3.readnews.com!postnews.google.com!news2.google.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail NNTP-Posting-Date: Fri, 10 Jun 2011 03:30:07 -0500 Date: Fri, 10 Jun 2011 01:30:03 -0700 From: Patricia Shanahan User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10 MIME-Version: 1.0 Newsgroups: comp.lang.java.programmer Subject: Re: Call by Result References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Lines: 26 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 70.230.199.66 X-Trace: sv3-dE0f2jcHMVs+lRb+cbDjFjKBXY8obegsLjMJs/fShMOUYqbGaJfF9UuKtMNcX7axQraffcBDaE7DNrY!npQHp6AjvbqrZEmxRYYSsh90DtQ/ax8LT10l2ZBZ7uUDuHrOUkxa1yQBpGUw6OwIQSLR7z3pIdyW!lIRvEdLmcwnoXYxnp/WSLUkpysrVHo1sA4Z9iWtIjS8VUw== X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2158 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:5171 On 6/9/2011 11:03 PM, Gene Wirchenko wrote: > Dear Java'ers: > > I wish to call by result with a method. Is it possible? If not, > can it be easily simulated in an unnasty way? > > 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. Exceptions provide an alternative. Rather than returning a didItWork boolean, return the String if it did work, and throw an exception if it did not work. In addition to allowing the method to return its primary result, it also allows for passing back more information in the case of failure, which can lead to better reporting. Patricia