📲 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

30 practice questions on error handling

🚀 JavaScript Error Handling – 30 Practice Questions

🔹 Beginner Level (1–10)

1.

Write a program that divides two numbers using try...catch and handles division by zero.

2.

Create a try...catch block to handle an undefined variable error.

3.

Write code that parses invalid JSON and catches the error.

4.

Use finally to print “Execution Completed” whether error occurs or not.

5.

Create a function that throws an error if a number is negative.

6.

Handle an error when accessing a property of undefined.

7.

Write a program that catches invalid user input (non-number).

8.

Use try...catch to handle NaN results.

9.

Create a custom error using throw for empty string input.

10.

Write a program where catch prints only error.message.


🔹 Intermediate Level (11–20)

11.

Create a function that checks age and throws error if age < 18.

12.

Write a program to validate email format using throw.

13.

Handle JSON API response errors using try...catch.

14.

Create nested try...catch blocks.

15.

Write a function that throws different errors for:

  • negative number
  • zero
  • valid number

16.

Use finally to close a simulated database connection.

17.

Handle array index out-of-bound error manually.

18.

Create a calculator that throws error for invalid operator.

19.

Write code that re-throws an error after catching it.

20.

Handle missing function arguments using throw.


🔹 Advanced Level (21–30)

21.

Create a custom error class using class extends Error.

22.

Handle asynchronous errors using try...catch with async/await.

23.

Write an API call using fetch and handle network errors.

24.

Create a retry mechanism if API fails (use error handling).

25.

Differentiate between SyntaxError, ReferenceError, and TypeError in code.

26.

Log errors to console and also store them in an array.

27.

Create a global error handler for a web app.

28.

Write a function that validates multiple fields and throws combined errors.

29.

Handle file upload errors (simulate using conditions).

30.

Build a form validator that:

  • throws errors
  • catches them
  • displays user-friendly messages

💡 Bonus Tip (Important)

👉 In real projects:

  • Use try...catch for runtime errors
  • Use throw new Error() for custom validation
  • Use finally for cleanup tasks


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