Error
A custom js Error class
by cent cent
HTML
<din id="test"></div>
JavaScript
window.g3 = window.g3 || {};
g3.Error = function (message, name, original) {
this.original = original;
this.name = name || 'Error.g3';
this.message = message || 'A g3.Error was thrown!';
(original)? this.stack = this.original.stack: this.stack = null;
this.message += '<br>---STACK---<br>' + this.stack;
};
var ClassEmpty = function() {};
ClassEmpty.prototype = Error.prototype;
g3.Error.prototype = new ClassEmpty();
g3.Error.prototype.constructor = g3.Error;
window.onerror = printError;
function printError(msg, url, line){
document.getElementById('test').innerHTML = msg+'<br>at: '+url+'<br>line: '+line;
return true;
}
//hit it!
//throw new g3.Error('Hey, this is an error message!', 'Error.Factory.g3');
throw new g3.Error('Hey, this is an error message!', 'Error.Factory.g3', new Error());