emberjs/ember.js — pull request #1617 by stefanpenner (2012-12-23 04:38:47+00:00)
Title: Fixes: Safari's 'double finally on error bug'

Scumbag Safari
----------------------

Turns out safari (6.0.2) and potentially other webkits,
will execute finally twice, if an error is thrown in finally.

``` Javascript

count = 0;
try {

} finally {
count ++
throw new Error('bromg');
}

count
> 2
```

Those who gained some extra gray hair debugging this one:
* @kselden
* @wagenet
* @stefanpenner

Bug Demo: http://jsbin.com/usoquy/1/edit
known to be an issue in:
* Safari 6.0.2
* iOS 6 mobile safari
* maybe others

We also submitting a bug to [apple](http://bugreport.apple.com/), and it is `Problem ID: #12929607`

Interestingly the error will only be thrown once, but the
code up until the error is thrown, will be executed twice.

Although strange, it is rare during normal ideal execution
that this causes real issues, but when it does, it
is quite frustrating to debug.

Two new utility methods provide the 'safe' workaround:

``` Javascript
Ember.tryFinally(tryable, finalizer);
Ember.tryCatchFinally(tryable, catchable, finalizer);
```

These helpers try to abide by the languages try/catch/finally
semantics.

- Happy Holidays.