try { nonexistantfunction("hello"); } catch(err) { alert("An exception was caught:" + err); }