When should you use try/catch in JavaScript?
问题 When I'm developing normal web application with JavaScript, the try/catch statement is not needed usually. There's no checked exception, File IO or database connection in JavaScript. Is try/catch statement useful in JavaScript? When can I use it? 回答1: Use it whenever code you are running might throw an exception. Remember that you can throw your own errors — most of the try…catch stuff I use is for catching my own exceptions. 回答2: try...catch blocks are generally encourages to be used less,