Path: csiph.com!usenet.pasdenom.info!gegeweb.org!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Jukka Lahtinen Newsgroups: comp.lang.java.programmer Subject: Re: can't return value Date: Thu, 13 Sep 2012 15:06:18 +0300 Organization: A noiseless patient Spider Lines: 20 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 8bit Injection-Info: ipa.eternal-september.org; posting-host="a5a3e65df26a45e8ef56e0325d9681f2"; logging-data="3623"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19vU2XmHLsPaXB0LFLqiM1T" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1 (gnu/linux) Cancel-Lock: sha1:Vwhg8PXV+gY6bdsvH6gO/v6C1LQ= sha1:an7+7bPaAUEvxz8ooEcs3sKrFo8= X-no-archive: yes Xref: csiph.com comp.lang.java.programmer:18733 Stuart writes: > On 9/13/12 bilsch wrote: >> Based on what Jukka said I got it to work without using the for loop. >> OK. Now I see what Jukka meant by initializing to NULL. But I don't >> know what exception to throw for 'misssing return statement'. Also I > What Jukka probably meant to say is that you could throw an exception in > case your method could not extract a surname from the passed string. Like No, I just meant that the original code WILL throw an ArrayIndexOutOfBoundsException if it doesn't find a space. Right here in the String#charAt method, when i reaches wholeName.length(): for (int i = 0; i <= wholeName.length(); i++){ if (wholeName.charAt(i)== ' '){ and bilsh probably wants to avoid it. -- Jukka Lahtinen