try { var x = -1; if (x<0) throw "smallerthan0Error"; } catch(err){ alert (err + "was thrown"); }