diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index d30bef49..e88c3655 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -1129,9 +1129,13 @@ getJasmineRequireObj().DelayedFunctionScheduler = function() { getJasmineRequireObj().ExceptionFormatter = function() { function ExceptionFormatter() { this.message = function(error) { - var message = error.name + - ': ' + - error.message; + var message = ''; + + if (error.name && error.message) { + message += error.name + ': ' + error.message; + } else { + message += error.toString() + ' thrown'; + } if (error.fileName || error.sourceURL) { message += " in " + (error.fileName || error.sourceURL); diff --git a/spec/core/ExceptionFormatterSpec.js b/spec/core/ExceptionFormatterSpec.js index 88d83938..5c4ead71 100644 --- a/spec/core/ExceptionFormatterSpec.js +++ b/spec/core/ExceptionFormatterSpec.js @@ -35,7 +35,14 @@ describe("ExceptionFormatter", function() { message = exceptionFormatter.message(sampleV8); expect(message).toEqual('A Classic Mistake: you got your foo in my bar'); + }); + it("formats thrown exceptions that aren't errors", function() { + var thrown = "crazy error", + exceptionFormatter = new j$.ExceptionFormatter(), + message = exceptionFormatter.message(thrown); + + expect(message).toEqual("crazy error thrown"); }); }); diff --git a/src/core/ExceptionFormatter.js b/src/core/ExceptionFormatter.js index 29e17d46..1af2f75f 100644 --- a/src/core/ExceptionFormatter.js +++ b/src/core/ExceptionFormatter.js @@ -1,9 +1,13 @@ getJasmineRequireObj().ExceptionFormatter = function() { function ExceptionFormatter() { this.message = function(error) { - var message = error.name + - ': ' + - error.message; + var message = ''; + + if (error.name && error.message) { + message += error.name + ': ' + error.message; + } else { + message += error.toString() + ' thrown'; + } if (error.fileName || error.sourceURL) { message += " in " + (error.fileName || error.sourceURL);