Programming/JavaScript/errorHandler()

From Skypher

Jump to: navigation, search

Main Page
├─▼Programming
│ ├─▼JavaScript
│ │ ├─▷JSSh
│ │ ├─○JavaScriptStringEncode()
│ │ ├─○serialize()
│ │ ├─○visualize()
│ │ ├─○stackDump()
│ │ ├─●errorHandler()
│ │ └─○Array extensions
│ ├─▷ASP
│ └─○Chimera code
└─▷Hacking

Contents


The Code

window.onerror = function errorHandler(sError, sFile, sLineno) {
	// If the last node is a script tag with a src attribute, it is likely
	// to be the cause of the error, so display the src attribute's value:
	var oLastNode = document;
	while(oLastNode.childNodes.length > 0) {
		oLastNode = oLastNode.childNodes[oLastNode.childNodes.length - 1];
	}
	var sLastScript = oLastNode.tagName == "SCRIPT" && typeof(oLastNode.src) !== "undefined"?
		"(Last script: " + oLastNode.src + ")\r\n" : "";
	if (confirm(
		"JavaScript Error caught\r\n" +
		"Error: " + visualize(sError) + "\r\n" +
		"In line " + visualize(sLineno) + " of file " + visualize(sFile) + "\r\n" +
		sLastScript +
		"\r\n" +
		"(Press OK to ignore or CANCEL for more information)\r\n" +
		stackDump(1)
	) && confirm(
		"JavaScript Error caught\r\n" +
		"Error: " + visualize(sError) + "\r\n" +
		"In line " + visualize(sLineno) + " of file " + visualize(sFile) + "\r\n" +
		sLastScript +
		"\r\n" +
		"(Press OK to see ignore or CANCEL to terminate the script)\r\n" +
		stackDump(1, true)
	)) {
		return true;
	};
	return false;
}
Personal tools