Re: Extended break

From: Alex Hunsley (lard_at_tardis.ed.ac.molar.uk)
Date: 12/09/03


Date: Tue, 09 Dec 2003 16:24:23 +0000

Adam wrote:

>>>>Heh, true.
>>>>So another approach, nicely using language features:
>>>>make your recursive method throw I_Found_It_Exception.
>>>>Put your most outer call to recursiveMethod it a try-catch block,
>>>>You can just do nothing in the catch block then.
>>>>:)
>>>
>>>
>>>Actually, I'd discourage that kind of use of an exception. Exceptions
>
> are
>
>>>for "bad" things.
>>>
>>> - Virgil
>>
>>Agreed. An exception shouldn't be used here; as Virgil noted, exceptions
>>are for When Things Go Wrong, and not for catching a condition which you
>>expect in normal (correct) running of a program.
>
>
> I'm aware of that, and that's why i've put a smiley there.
> The approach was meant to be a contrary for goto statement.
>
>
>>One of the reasons for
>>this is that Exceptions are expensive to throw; I remember reading one
>>estimate that you waste ten times as much execution time throwing an
>>exception as setting a signalling flag or somesuch other thing (which
>>would suffice).
>
>
> Not always necessary true.
> For a speed-performance tuning
> I've seen using exceptions to end
> a simple loop:
> <code>
> int[] someArray = ...
> try{
> for(int i=0;;++i) someArray[i] = ....
> }catch(IndexOutOfBoundsException e){}
> </code>
> as it was faster not to check i<someArray.length every time.
> (I'm just not sure if it was in java though...)
>
> Adam
I see what you mean...
I think it's careless, though, to rely on an exception when you hit the
end of an array, rather than *knowing* how far you should go. It will
also be more confusing to other programmers seeing the code who are
trying to work out what's going on!
It may function as an optimisation, as you say. Whether it's worth it,
vs. readability/maintainability, is worth examining though.

alex



Relevant Pages

  • Re: ABBA, Part Two
    ... worth being jailed then deported for the sweet pleasure of busting the ... Kind AND gracious is our Adam. ...
    (soc.culture.scottish)
  • Re: Difference between 1st and 2nd Class on ICE and IC Trains?
    ... for what it is worth, I have almost never had any problem finding ... (The exception was traveling during the first day ...
    (rec.travel.europe)
  • Re: Try Finally...
    ... Delphi's sysutils.pas is worth having a fight about the entire exception ... handling in Delphi over. ... I rarely force an exit upon an exception, and I have a goal that most ...
    (comp.lang.pascal.delphi.misc)
  • GetWebResponse times out over HTTPS
    ... When making a webservice call to upload more than 30KB worth of data ... WebException.Timeout exception. ... I have no trouble sending like 300KB worth of data over HTTP. ...
    (microsoft.public.dotnet.framework.compactframework)
  • Using ASP.NET 2.0 Roleprovider against AzManStore in ADAM
    ... I've been able to setup an AzMan store within ADAM and authorize a ... for the roles I have setup with AzMan. ... Exception has been thrown by the target of an invocation. ... My ADAM and IIS instances are on separate servers within the same ...
    (microsoft.public.dotnet.framework.aspnet.security)