Starlit Daily

📚 › 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.

← العودة إلى الدورة