You could create a function which wraps a function within try catch.
Well, here's an example:
function good1() { console.log("works"); }
function bad() { throw "i throw somethuing"; }
function good2(someParameter) {
console.log("works with paraemter too.. =>", someParameter);
}
function runSafe(fn) {
try {
return fn();
} catch(error) {
console.error(error);
return null;
}
}
var results = [
runSafe(good1),
runSafe(bad),
runSafe(function() { return good2("Yes it does!"); }
];
console.log(results);
Not clear about your intent. Complain about the following, and that may give me better understanding. Note test() will ALWAYS report "calling function1" - there is no function1.
<html> <head> <script type="text/javascript""> function test() { var msg; try { msg = "calling function1"; function1(); msg = "function1 passed - calling function2"; function2(); msg = "function2 passed - calling function3"; function3() msg = "all functions passed"; } catch (e) { ;// do something useful here } return msg; }; function functiona() {;}; function functionb() {;}; function functionc() {;}; function test2() { try { functiona(); functionb(); functionc(); alert("all functions passed"); } catch (e) { ;// do something useful here } }; window.onload = function() { alert(test()); test2(); }; </script> </head> <body> <div>some content here</div> </body> </html>