function and exception in JavaScript