Free tutorials & notes in Hindi & English · Clean code examples 🧰 मुफ़्त PDF और फ़ोटो टूल्स →
🔴 Advanced  ·  Lesson 23

Exception Handling

Exception Handling क्या है?

Exception program चलते समय होने वाली एक अनचाही घटना है जो सामान्य flow को रोक देती है — जैसे zero से भाग देना, array की सीमा से बाहर जाना, या गायब file खोलना। Exception handling ऐसी errors को crash हुए बिना संभालने देता है।

पाँच Keywords

Keywordउपयोग
tryजोखिम भरे code को लपेटता है।
catchexception होने पर संभालता है।
finallyहमेशा चलता है (cleanup)।
throwmanually exception फेंकता है।
throwsबताता है कि method exception फेंक सकता है।

उदाहरण

Java
try {
    int x = 10 / 0;
} catch (ArithmeticException e) {
    System.out.println("Cannot divide by zero");
} finally {
    System.out.println("Done");
}
▶ Output
Cannot divide by zero
Done

Checked vs Unchecked

प्रकारकब checkउदाहरण
CheckedCompile time (संभालना ज़रूरी)IOException, SQLException
UncheckedRuntimeArithmeticException, NullPointerException
💡 क्यों संभालें?

बिना handling के एक error पूरा program crash कर देती है। handling से friendly message दिखाकर program चलता रहता है।

⚠️ आम गलती

खाली catch {} block कभी न छोड़ें — यह bugs छुपाता है। कम से कम error log करें।

सारांश

  • Exceptions normal flow रोकती हैं; handling crash रोकती है।
  • Keywords: try, catch, finally, throw, throws।
  • finally हमेशा चलता है; checked ज़रूरी, unchecked runtime पर।
← Back to Java Tutorial
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

💻 लाइव कोड एडिटर

इस पेज के प्रोग्राम यहीं तैयार हैं — चलाएँ, बदलें और सीखें। कुछ भी इंस्टॉल किए बिना।
OneCompiler द्वारा संचालित। कोड एडिटर में अपने आप आ जाता है — Run दबाकर आउटपुट देखें। अगर एडिटर न खुले तो नए टैब में खोलें.
अगला topicCollections (ArrayList, HashMap) आपकी प्रगति: 23 / 61 (38%) · Lesson 24 / 61 आगे बढ़ें →

यह lesson कैसा लगा?

आपकी राय से हम content और बेहतर बनाते हैं।

अपना review और सुझाव लिखें (वैकल्पिक)

Review approve होने के बाद आपका नाम और शहर इसके साथ public दिख सकते हैं। Email या phone न लिखें।

▶ CodingEasily on YouTube

Video से सीखें – आसान Hindi में

चुनी हुई video: RDBMS भाग 3 – Class XI Commerce IT

▶ Channel subscribe करें