diff --git a/src/lib/errors.js b/src/lib/errors.js index 36686debd..d2f261548 100644 --- a/src/lib/errors.js +++ b/src/lib/errors.js @@ -1,15 +1,23 @@ var _ = require('./utils'); var errors = module.exports; +var canCapture = (typeof Error.captureStackTrace === 'function'); +var canStack = !!(new Error()).stack; + function ErrorAbstract(msg, constructor) { this.message = msg; Error.call(this, this.message); - if (process.browser) { - this.stack = ''; - } else { + + if (canCapture) { Error.captureStackTrace(this, constructor); } + else if (canStack) { + this.stack = (new Error()).stack; + } + else { + this.stack = ''; + } } errors._Abstract = ErrorAbstract; _.inherits(ErrorAbstract, Error);