📚 › JavaScript: make pages do things
13. Errors and try/catch
इस लेख का अनुवाद अपने आप होगा। अभी अंग्रेज़ी में दिखाया जा रहा है।
Code can fail. try runs code that might fail, and catch handles the error instead of stopping the whole program. Read the error message: it tells you what went wrong.
Handle errors where you can recover from them, such as a missing network response.
उदाहरण देखें
try {
null.length;
} catch (err) {
console.log("Something went wrong");
}
✍️ अब आपकी बारी
Use try and catch: in try throw new Error("oops"); in catch print the error message.