Catch errors
by efertone
JavaScript
var MyObject = {
test: function () {
console.log('exists');
},
cmd: function (method, parameters) {
console.log("call", method, "with parameters: ", parameters);
},
toString: function () {
return "MyObject";
}
};
window.onerror = function (msg, file, line) {
var matches = msg.match(/^Uncaught TypeError: ([a-zA-Z_]+) ([a-zA-Z_<>#]+) has no method '([a-zA-Z_]+)'/);
if (matches) {
eval(matches[2]).cmd(matches[3]);
} else {
console.log('not matched');
}
// console.log(arguments);
return true;
};
MyObject.xxx('hurray');