I'd argue that throws in Ruby and Python are not safe, either!

Here's a simple example:

function doSomething(array) {
  for (var i = 0; i < array.length; i++) {
    mightThrow(array[i]);
  }
}

If you call `doSomething(list)` then there's no way for you to know
how many items in the list were processed.  Precisely *because* it
jumps up the call stack, there's no way to handle this without
catching at *every* level, not just the level that can correct from
the error.

At best, it's expensive.  At worst, it leads to indeterminate state,
and cases where resources are not properly cleaned up.  In real world
examples, I've seen fd leaks, sockets hung open until they timed out,
event listeners never removed, streams that never stop downloading,
etc.  (And that was *before* coming to Node!)

PHP avoids this problem by tearing down the VM after each request, so
leaks aren't a real issue (there are obviously other issues with this
approach).  Pure functional languages avoid the problem by having
isolated crash-only architectures.

The correct way to handle this in a stateful imperative language like
JavaScript is to kill the process and clean up all the resources.


On Thu, Apr 4, 2013 at 8:46 PM, Mark Hahn <[email protected]> wrote:
> Short version:  Python and Ruby are usually not run asynchronously.
> Exceptions and async don't play well together,
>
>
>
> On Thu, Apr 4, 2013 at 8:40 PM, Forrest L Norvell <[email protected]>
> wrote:
>>
>> On Thu, Apr 4, 2013 at 5:39 PM, Nicolas Grilly <[email protected]>
>> wrote:
>>>
>>> As of the way exception handling works, V8 is not that different from
>>> Python and Ruby. In Python and Ruby, you can throw an exception anywhere,
>>> and catch it somewhere else, without "leaking references" or "creating some
>>> other sort of undefined brittle state", if your code correctly releases
>>> allocated ressources using finally statements. What makes JavaScript
>>> different?
>>
>>
>> JavaScript itself is no safer or more dangerous than Ruby or Python.
>> However, putting everything in try/catch/finally clauses is expensive (i.e.
>> they can't be fully optimized by V8). Also wrapping asynchronous calls in
>> try/catch is often exactly what you don't want to do, if getting meaningful
>> error messages is your goal. Domains are intended to be a relatively
>> inexpensive mechanism to capture information about the cause of a crash that
>> extends over the length of an asynchronous call chain. They're not a
>> general-purpose error recovery mechanism.
>>
>> Realistically speaking, there's no way to write a general "async finally"
>> in Node. Side effects are just too pervasive, and while if you're careful
>> you can ensure that resources are properly cleaned up, it's not a problem
>> that can be automated. Node 0.8 and 0.10 domains included a domain.dispose()
>> method that tries to clean up the EventEmitters bound to a domain, but it's
>> heuristic and will be deprecated in 0.12.
>>
>> F
>>
>> --
>> --
>> Job Board: http://jobs.nodejs.org/
>> Posting guidelines:
>> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
>> You received this message because you are subscribed to the Google
>> Groups "nodejs" group.
>> To post to this group, send email to [email protected]
>> To unsubscribe from this group, send email to
>> [email protected]
>> For more options, visit this group at
>> http://groups.google.com/group/nodejs?hl=en?hl=en
>>
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "nodejs" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>
>
> --
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
>
> ---
> You received this message because you are subscribed to the Google Groups
> "nodejs" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

-- 
-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to