Throwing Exceptions java In Hindi

Throwing Exceptions java In Hindi

जावा प्रोग्रामिंग में किसी प्रोग्राम एक्सेप्शन को थ्रो करने के लिए थ्रो कीवर्ड का यूज़ किया जाता हैं। जहा जावा यूजर किसी कस्टम प्रोग्राम एक्सेप्शन को थ्रो करने के लिए इसे इंडीकेट कर सकते हैं. जिससे की मौजूदा प्रोग्राम में यूजर डिफाइन फंक्शन मेथड के अंदर या प्रोग्राम में किसी स्पेशल इवेंट ट्रिगर के कारण से कोई प्रोग्राम एरर या एक्सेप्शनल कंडीशन डेवलप हुई है। कस्टम जावा एक्सेप्शन थ्रो करके, जावा यूजर किसी प्रोग्राम के नॉर्मल एक्सेक्यूशन प्रोसेस या फ्लो को स्टॉप कर सकते हैं, और मौजूदा प्रोग्राम के डिफ़ॉल्ट फ्लो कंट्रोल को एक प्रॉपर मैच कैच ब्लॉक में मूव या ट्रांसफर कर सकते हैं. जहाँ मल्टीप्ल यूजर डिफाइन प्रोग्राम एक्सेप्शन कंडीशन को हैंडल या मैनेज किया जा सकता है।

Throwing Exceptions java In Hindi

Throwing Exceptions with the Java throw Keyword.

किसी जावा प्रोग्राम में थ्रो कीवर्ड का यूज़ यूजर डिफाइन प्रोग्राम सोर्स कोड से कस्टम एक्सेप्शन को क्लियर आर्डर में थ्रो करने में किया जाता है। जावा यूजर अपनी प्रोग्रामिंग जरूरतों के अनुसार जावा लाइब्रेरी में बिल्ट-इन प्रोग्राम एक्सेप्शन जैसे, NullPointerException या IOException और कस्टम यूजर डिफाइन एक्सेप्शन जैसे, जावा यूजर अपनी सेल्फ एक्सेप्शन को भी डिफाइन करते हैं, और जरूरत पड़ने पर इन दोनों एक्सेप्शन को प्रोग्राम में थ्रो कर सकते हैं।

Syntax for Throwing Exceptions.

throw new ExceptionType(“Custom Exception Error Message”);

Here in Throwing Exceptions.

  • यहाँ जावा प्रोग्राम में ExceptionType वह यूजर डिफाइन जावा एक्सेप्शन का एक टाइप या नेचर है, जिसे जावा यूजर मौजूदा प्रोग्राम में थ्रो कर रहे हैं. यहाँ इसमें यूजर डिफाइन कोई भी क्लास हो सकती है. जो जरूरत पड़ने पर Throwable सिचुएशन को एक्सटेंड करती है।
  • इसी प्रकार “Error Message” एक ऑप्शनल यूजर डिफाइन कस्टम एक्सेप्शन मैसेज है, जो यूजर डिफाइन एक कस्टम एक्सेप्शन एरर इनफार्मेशन को प्रोग्राम में इंडीकेट करता है।

Throwing Built-in Exceptions in Java.

जावा यूजर किसी प्रोग्राम में NullPointerException या ArithmeticException, आदि कस्टम प्रोग्राम एक्सेप्शन को थ्रो कीवर्ड जैसे, कोई भी बिल्ट-इन एक्सेप्शन मैसेज कंडीशन को मौजूदा प्रोग्राम में थ्रो कर सकते हैं।

Example of throwing an ArithmeticException in a Java program.

public class ThrowExcceptionIllustration {

    public static void main(String[] args) {

        int p = 10;

        int q = 0;

        try {

            if (q == 0) {

                throw new ArithmeticException(“here p & q variable divide zero is not permitted”);

            } else {

                int output = p / q;

            }

        } catch (ArithmeticException e) {

            System.out.println(“here user define custom Exception caught – ” + e.getMessage());

        }

    }

}

In this example.

  • यहाँ इस प्रोग्राम में जब q 0 हो, तो यह क्लियर आर्डर में एक ArithmeticException को थ्रो करते हैं, जिससे की इसमें ज़ीरो से डिवीज़न वैल्यू को स्टॉप किया जा सके। यहाँ इसमें यूजर डिफाइन कस्टम एक्सेप्शन प्रोग्राम क्रिएटेड catch ब्लॉक में कैच हो जाता है, और रिजल्ट के रूप में एक सही मैसेज को डिस्प्ले किया जाता है।

Throwing a Custom Exception in a Java Program.

जावा यूजर जावा प्रोग्राम में एक बिल्ट-इन लाइब्रेरी प्रोग्राम एक्सेप्शन के जैसे ही, throw कीवर्ड को अप्लाई करके एक कस्टम एक्सेप्शन (एक यूज़र-डिफ़ाइंड मैन्युअल एक्सेप्शन) एरर मैसेज को भी थ्रो कर सकते हैं।

An example of throwing a custom exception in Java is InsufficientCourseException.

public class InsufficientCourseException extends Exception {

    public InsufficientCourseException(String message) {

        super(message);

    }

}

public class Student {

    private double duration;

    public Student(double duration) {

        this.duration = duration;

    }

    public void Selection(double amount) throws InsufficientCourseException {

        if (amount > duration) {

            throw new InsufficientCourseException(“Invalid course for selection ” + amount);

        } else {

            duration -= amount;

            System.out.println(“The selected course duration – ” + duration);

        }

    }

public static void main(String[] args) {

        Student data = new Student(999);

        try {

            data.selection(10999); // here This will throw an InsufficientCourseException error

        } catch (InsufficientCourseException e) {

            System.out.println(“user define program Exception caught – ” + e.getMessage());

        }

    }

}

Here in this example.

  • यहाँ इस प्रोग्राम में Selection() फंक्शन मेथड यह चेक करती है कि सलेक्शन कोर्स  अमाउंट अवेलेबल कोर्स duration से ज़्यादा है, या नहीं है।
  • यदि यहाँ ऐसा होता है, तो यह एक InsufficientCourseException एक कस्टम एरर मैसेज इनफार्मेशन को डिस्प्ले करता है।
  • इसी प्रकार एक्सेप्शन catch ब्लॉक में डिफाइन एक मैसेज है, जहाँ यह एक यूजर डिफाइन कस्टम इन्फो मैसेज को डिस्प्ले करते हैं।

Leave a Reply