Skip to content

Instantly share code, notes, and snippets.

@ChecksumFailed
Created June 12, 2024 18:26
Show Gist options
  • Save ChecksumFailed/811cc14d5661346cc989680c1ced7664 to your computer and use it in GitHub Desktop.
Save ChecksumFailed/811cc14d5661346cc989680c1ced7664 to your computer and use it in GitHub Desktop.
/**
* Method to handle try/catch
* @param {Function} tryMethod - Method to try
* @param {Function} catchMethod - Method to call in case of error
* @param {Array} methodParams - Array of arguments to call with function.apply
* @private
* @returns Result of tryMethod or exception
*/
_tryCatch: function (tryMethod, catchMethod) {
var context = this;
return function (methodParams) {
try {
return tryMethod.apply(context, methodParams);
} catch (ex) {
ex.caller = tryMethod.name || '';
methodParams.unshift(ex);
catchMethod.apply(context, methodParams);
return ex;
}
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment