📲 Download Utility Tools Apps

EMI Calculator

Download EMI Calculator

SOA Games

Download SOA Games

SOA Technology App

Download SOA Technology

BMI Checker

Download BMI Checker

Task Jira

Download Task Jira

Laughing Adda

Download Laughing Adda

📅 हिंदी कैलेंडर ऐप डाउनलोड करें

Download Shubhcalendar App

1️⃣4️⃣ JavaScript Error Handling

JavaScript Error Handling helps you manage runtime errors so your program doesn’t crash unexpectedly. Let’s break down each keyword clearly:


🔹 1. try

The try block contains code that might cause an error.

👉 JavaScript will attempt to run this code.

try {
let result = 10 / x; // x is not defined → error
}

🔹 2. catch

The catch block runs if an error occurs in try.

👉 It receives the error object (you can name it anything, usually err).

try {
let result = 10 / x;
} catch (err) {
console.log("Error occurred:", err.message);
}

✔ Output:

Error occurred: x is not defined

🔹 3. finally

The finally block always executes, whether an error happens or not.

👉 Useful for cleanup tasks (closing connections, stopping loaders, etc.)

try {
console.log("Trying...");
} catch (err) {
console.log("Error:", err.message);
} finally {
console.log("This always runs");
}

✔ Output:

Trying...
This always runs

🔹 4. throw

The throw statement is used to create your own custom error.

👉 You can throw:

  • String
  • Number
  • Boolean
  • Object (best practice: use Error)
function checkAge(age) {
if (age < 18) {
throw new Error("You must be 18 or older");
}
return "Access granted";
}try {
console.log(checkAge(16));
} catch (err) {
console.log(err.message);
}

✔ Output:

You must be 18 or older

🔥 Full Example (All Together)

try {
let age = 15; if (age < 18) {
throw new Error("Underage user");
} console.log("Access granted");} catch (err) {
console.log("Caught error:", err.message);} finally {
console.log("Execution finished");
}

🧠 Key Points

  • try → test code
  • catch → handle errors
  • finally → always runs
  • throw → create custom errors

🚀 Interview Tip

  • Always use Error object in throw:
throw new Error("Something went wrong");


AI Spiritual Tools & Interactive Experiences

Explore powerful AI-driven tools for daily guidance, spirituality, fun quizzes, and self-discovery.

Today’s Quote

Get inspiring daily quotes powered by AI to motivate and guide your day.

Explore Now

AI Tarot Card Reader

Reveal insights about your future, love, and career with AI tarot readings.

Read Tarot

Love Match Calculator

Check compatibility and love predictions using AI-based analysis.

Check Match

Fortune Cookie

Open an AI fortune cookie and receive wisdom, luck, and fun messages.

Open Cookie

Quiz Categories

Engage with knowledge-based and fun quizzes across multiple categories.

Start Quiz

Panchang Calendar

View daily Panchang, auspicious timings, tithi, nakshatra, and festivals.

View Panchang

Online Numerology

Discover your destiny number, life path, and numerology predictions.

Calculate Now

Spiritual Feeds

Stay connected with spiritual thoughts, mantras, and divine content.

View Feeds

Quiz Hub

Attempt trending quizzes on GK, spirituality, festivals, and more.

Explore Quizzes