chuck.js/app/Lib/Utilities/Exception.js
2014-08-30 16:27:05 +02:00

38 lines
No EOL
888 B
JavaScript
Executable file

define([
],
function() {
function Exception(/* arguments */) {
var message = [];
for (var i = 0; i < arguments.length; i++) {
var arg = arguments[i];
if (typeof arg == "object") {
var name = this.getTypeOfObject(arg);
message.push(name);
} else {
message.push(arg);
}
};
this.message = message.join(" ");
var e = Error.call(this, this.message);
console.log(e.stack)
}
Exception.prototype = Object.create(Error.prototype);
Exception.prototype.toString = function() {
return this.message;
};
Exception.prototype.getTypeOfObject = function (obj) {
var funcNameRegex = /function (.{1,})\(/;
var results = (funcNameRegex).exec((obj).constructor.toString());
return (results && results.length > 1) ? results[1] : "";
}
return Exception;
});