try catch for js functions