diff --git a/lodash.js b/lodash.js index f0b0b6bbe..fdc5d7ab7 100644 --- a/lodash.js +++ b/lodash.js @@ -12926,7 +12926,7 @@ try { return apply(func, undefined, args); } catch (e) { - return isError(e) ? e : new Error(e); + return isObject(e) ? e : new Error(e); } }); diff --git a/test/test.js b/test/test.js index 78dcdaa22..9672c9647 100644 --- a/test/test.js +++ b/test/test.js @@ -1482,6 +1482,20 @@ assert.ok(lodashStable.isEqual(actual, Error('x'))); }); + QUnit.test('should preserve custom errors', function(assert) { + assert.expect(1); + + function CustomError(message) { + this.name = 'CustomError'; + this.message = message; + } + + CustomError.prototype = lodashStable.create(Error.prototype); + + var actual = _.attempt(function() { throw new CustomError('x'); }); + assert.ok(actual instanceof CustomError); + }); + QUnit.test('should work with an error object from another realm', function(assert) { assert.expect(1);