Different schools of thought!

In try-catch block (the only place where exceptions must live) you say TRY
to execute this code BUT may happens something you don't expect; in this
case CATCH the error to find a way to resolve it (you could then verify what
type of problem occurs).

w3schools definition:"The try...catch statement allows you to test a block
of code for errors. The try block contains the code to be run, and the catch
block contains the code to be executed if an error occurs."

I don't know what kind of operation js makes when you throw an exeption but
IMHO it would be a bit more resource consuming than simply exit.


But I agree with your on the fact that we need this functionality to be part
of the mootools API too.


-Vito-



--
-----------
Tafuni Vito
v...@vitotafuni.com
---------------------------------------------
"Verba volant, scripta manent... data corrupted"


2010/10/23 אריה גלזר <arieh.gla...@gmail.com>

> Exception: An action that is not part of ordinary operations or standards.
>>  They will be used to control "program flow interruption" and not for
>> program "flow branching" that could lead to difficult-to-maintain code.
>> http://www.informit.com/articles/article.aspx?p=433387
>> Read this article... is about java but the principle is the same.
>>
>> Exception is something more complex than a simple break in a for... I
>> don't think you go to the mechanic to empty the ashtray of your car!
>>
>>
> But they way we use JS is much more complex than a for iteration. Passing
> by lambas and such is something that does require a stronger flow control
> mechanism. An exception is a standard way in which a Class (in normal OOP)
> can communicate with it's the execution tree. Exception doesn't always mean
> an error. The thing is - a good use of exceptions requires that the user
> expects them. In the above case, the real problem is that although the Break
> function will work fine in a normal $each loop, which already wraps the
> iteration with a try-catch, using it in a normal iteration will break the
> code. Since lambdas are supposed to be concealed, it breaks the concept of
> encapsulation, creating a dependency.
> This can be fixed with 2 solutions -
> 1. a language construct for breaking such iterations.
> 2. A solid and consistent API. The reason I didn't put this up as a Forge
> plugin is that I think this concept is only valid if it's a part of the
> mootools API and completely consistent throughout all iteration APIs.
>
>
>>
>>
>>
>> -Vito-
>>
>>
>>>
>>>> -Vito-
>>>>
>>>>
>>>>
>>>> --
>>>> -----------
>>>> Tafuni Vito
>>>> v...@vitotafuni.com
>>>> ---------------------------------------------
>>>> "Verba volant, scripta manent... data corrupted"
>>>>
>>>>
>>>> 2010/10/22 keif <god.dre...@gmail.com>
>>>>
>>>> Zing, thanks for pointing that out, I was being lazy and not even
>>>>> looking in the console...
>>>>>
>>>>> On Oct 21, 6:00 pm, Sean McArthur <sean.mons...@gmail.com> wrote:
>>>>> > Pop open console, and you'll see that it's throwing errors for
>>>>> illegal break
>>>>> > statements. :)
>>>>> >
>>>>> >
>>>>> >
>>>>> > On Thu, Oct 21, 2010 at 2:58 PM, keif <god.dre...@gmail.com> wrote:
>>>>> > > I'm sorry, break doesn't work?
>>>>> > >http://jsfiddle.net/5Hm4w/2/
>>>>> >
>>>>> > > broke my two arrays (one of elements, one of numbers) - maybe I'm
>>>>> > > misunderstanding the question, lack of sleep will do that.
>>>>> >
>>>>> > > On Oct 21, 12:17 pm, Perrin Perrin <stardistroye...@gmail.com>
>>>>> wrote:
>>>>> > > > yes.
>>>>> >
>>>>> > > > On Thu, Oct 21, 2010 at 11:00 AM, stratboy <em...@reghellin.com>
>>>>> wrote:
>>>>> > > > > Good. 1 question: do array.every and array.some process the
>>>>> elements
>>>>> > > > > ALWAYS in sequence from index 0 to length-1? Or are they casual
>>>>> or not
>>>>> > > > > always in sequence? I know I can take a look to the source, but
>>>>> I'm
>>>>> > > > > lazy and I also know that YOU know :)
>>>>> >
>>>>> > > > > On 21 Ott, 17:17, Aaron Newton <anut...@gmail.com> wrote:
>>>>> > > > > > Or use array.some and return true when you want to stop.
>>>>> >
>>>>> > > > > > -Aaron
>>>>> >
>>>>> > > > > > Sorry for any typos. Big fingers , tiny buttons.
>>>>> >
>>>>> > > > > > On Oct 21, 2010, at 7:41 AM, stratboy <em...@reghellin.com>
>>>>> wrote:
>>>>> >
>>>>> > > > > > > :) Thank you Mr. Glazer! :)
>>>>> >
>>>>> > > > > > > On 21 Ott, 16:37, אריה גלזר <arieh.gla...@gmail.com>
>>>>> wrote:
>>>>> > > > > > >> Here:http://gist.github.com/638585
>>>>> >
>>>>> > > > > > >> Basically replaced the old $each with a new one that
>>>>> supports
>>>>> > > Break
>>>>> > > > > (will
>>>>> > > > > > >> only work for 1.3).
>>>>> >
>>>>> > > > > > >> example:http://jsfiddle.net/ariehg/bBKJm/
>>>>> >
>>>>> > > > > > >> On Thu, Oct 21, 2010 at 2:34 PM, Rolf -nl <
>>>>> plentyofr...@gmail.com
>>>>> >
>>>>> > > > > wrote:
>>>>> > > > > > >>> yes, nice n dirty with an exception..hehe..
>>>>> > > > > > >>> or use a while and a flag to stop the while loop (when
>>>>> you find a
>>>>> > > > > > >>> result or something)
>>>>> >
>>>>> > > > > > >>> On Oct 21, 2:31 pm, אריה גלזר <arieh.gla...@gmail.com>
>>>>> wrote:
>>>>> > > > > > >>>> No good way of doing it. I'm working on a nice
>>>>> workaround for
>>>>> > > it,
>>>>> > > > > but in
>>>>> > > > > > >>> the
>>>>> > > > > > >>>> mean time, the simplest way is to throw an exception
>>>>> >
>>>>> > > > > > >>>> On Thu, Oct 21, 2010 at 2:19 PM, stratboy <
>>>>> em...@reghellin.com>
>>>>> > > > > wrote:
>>>>> > > > > > >>>>> Hi! Is there a way to stop an each loop just like I can
>>>>> do with
>>>>> > > a
>>>>> > > > > for
>>>>> > > > > > >>>>> loop by using a break statement?
>>>>> >
>>>>> > > > > > >>>> --
>>>>> > > > > > >>>> Arieh Glazer
>>>>> > > > > > >>>> אריה גלזר
>>>>> > > > > > >>>> 052-5348-561
>>>>> > > > > > >>>> 5561
>>>>> >
>>>>> > > > > > >> --
>>>>> > > > > > >> Arieh Glazer
>>>>> > > > > > >> אריה גלזר
>>>>> > > > > > >> 052-5348-561
>>>>> > > > > > >> 5561
>>>>>
>>>>
>>>>
>>>
>>>
>>> --
>>> Arieh Glazer
>>> אריה גלזר
>>> 052-5348-561
>>> 5561
>>>
>>>
>>
>
>
> --
> Arieh Glazer
> אריה גלזר
> 052-5348-561
> 5561
>
>

Reply via email to