Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Try to desperately to capture exceptions and log them to the console.

View exceptionwrapper.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
// http://stackoverflow.com/questions/5931033/how-can-i-know-if-a-javascript-exception-occurred-in-a-phonegap-application-and
 
(function(){
 
window.onexception = function(e) {
console.log("Got an exception ", e, e.stack);
};
 
 
 
 
 
/**
* Wrap function with exception caturer.
* */
var captureExceptions = function(origFn) {
return function () {
try {
origFn.apply(this, arguments);
}
catch (e) {
window.onexception(e);
throw e;
}
};
};
 
 
/**
* Wraps callbacks in object methods
*
* */
var wrapCallbackFunction = function(obj, fnName, callbackIndex) {
var origFn = obj[fnName];
 
obj[fnName] = function() {
var args = [].slice.call(arguments);
args[callbackIndex] = captureExceptions(args[callbackIndex]);
origFn.apply(this, args);
};
 
};
 
 
 
wrapCallbackFunction(window, "addEventListener", 1);
wrapCallbackFunction(Node.prototype, "addEventListener", 1);
wrapCallbackFunction(window, "setTimeout", 0);
wrapCallbackFunction(window, "setInterval", 0);
 
 
 
}());
Owner
epeli commented

How to capture rest of the exceptions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.