/** * Let's throw an actual error if something is not an integer. * @param {[type]} x [description] * @param {[type]} y [description] */ function add(x,y){ if( isNaN(x) || isNaN(y) ){ throw new Error("OMG ERROR: I need numbers only k"); } else { // ensure we're adding numbers, not concatenating numeric strings return (x * 1) + (y * 1); } } var a; try { a = add(9); } catch(e) { // throw an actual error here. console.error( e.message ); }