try { setTimeout(function() { // error in the code }, 3000); } catch (e) { console.log( "won't work" ); }