function FatalError(message, file, line){
function toString() {
throw e;
}
var e = this;
e["@message"] = message;
e["@file"] = file || e.file || e.fileName;
e["@line"] = line || e.line || e.lineNumber;
if ("__defineGetter__" in e) {
e.__defineGetter__("message", toString);
e.__defineGetter__("description", toString);
} else {
e.message = e.description = {toString: toString};
}
// just in case, but not necessary
e.toString = e.valueOf = toString;
};
(FatalError.prototype = new Error).name = "FatalError";
how to use it?
throw new FatalError("this must be a joke!");
P.S. it won't work if Errors are not logged ( silent failures, definitively a problem for certain applications ;) )
When using a trying to log the error in a try/catch block, I get this error in the console:
ReplyDelete[unsupported: no toString() function in type object]
Any ideas?
you just demonstrated that FatalError works :D
ReplyDeleteIt's "unloggable" with normal procedures, so it's handy to spot silent failures in the middle of whatever code, or to break some trapped loop and check the behavior ... I know it sounds silly, but one day somebody will need it ( I actually did! )
excelent ;-) love this one
ReplyDelete