Common Java Exceptions In Hindi

Common Java Exceptions In Hindi

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

Common Java Exceptions In Hindi

Common Java exception list categories.

यहाँ आपको कुछ सबसे कॉमन लिस्ट ऑफ़ जावा एक्सेप्शन दिए गए हैं, जो जावा प्रोग्राम क्रिएट और एक्सेक्यूशन के दौरान उत्पन्न होते है.

NullPointerException/Unchecked Exception Java exception.

जावा प्रोग्राम में नलपॉइंट एक्सेप्शन तब जनरेट होता है, जब जावा में इन्सटाल्ड JVM किसी क्लास प्रोग्राम ऑब्जेक्ट की तरह एक नल रेफरेंस को यूज़ करने के लिए ट्राय करता है. जैसे, जावा प्रोग्राम में किसी नल ऑब्जेक्ट पर एक मेथड को कॉल करना या यूजर डिफाइन नल ऐरे डाटा को एक्सेस करना, आदि है।

Example of a Java NullPointerException.

   public class NullPointerIllustration {

        public static void main(String[] args) {

            String strvalue = null;

            // here This will throw NullPointerException in java program

            System.out.println(strvalue.length());

        }

    }

Result – Exception in thread “main” java.lang.NullPointerException

ArrayIndexOutOfBoundsException/Unchecked Exception Java Exception.

जावा प्रोग्राम में ऐरेइंडेक्सआउटऑफ़बाउंडएक्सेप्शन प्रोग्राम में तब जनरेट होती है, जब किसी जावा ऐरे प्रोग्राम में इनवैलिड इंडेक्स लोकेशन (एक ऐरे इंडेक्स, जो 0 से कम या एरे की लंबाई के बराबर या उससे अधिक हो) वाले यूजर डिफाइन ऐरे को इंडेक्स लोकेशन से एक्सेस करने की ट्राय की जाती है।

An example of an ArrayIndexOutOfBoundsException.

public class ArrayIndexOutOfBoundsIllustration {

        public static void main(String[] args) {

            int[] array = {9, 12, 14, 16, 22};

            // here This will throw ArrayIndexOutOfBoundsExceptionin this program

            System.out.println(array[7]);

        }

    }

Result – Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException: इंडेक्स 7, लेंथ 5 के लिए बाउंड्स से बाहर है

ArithmeticException/Unchecked Exception Java Exception.

जावा प्रोग्राम में अरिथमेटिकएक्सेप्शन एरर तब जनरेट होता है, जब जावा प्रोग्रामर द्वारा प्रोग्राम में कोई इनवैलिड या इललीगल अरिथमेटिक प्रोगाम ऑपरेशन करने का ट्राय किया जाता है. जैसे कि, ज़ीरो से किसी न्यूमेरिक वैल्यू को डिवीज़न करना, आदि है।

Java ArithmeticException example.

    public class ArithmeticExceptionIllustration {

        public static void main(String[] args) {

            int p = 30;

            int q = 0;

            // here This will throw an ArithmeticException error when it division by zero value

            System.out.println(p / q);

        }

    }

Result – Exception in thread “main” java.lang.ArithmeticException: / by zero

ClassNotFoundException/Checked Exception Java exception.

जावा प्रोग्राम में क्लासनॉटफाउंडएक्सेप्शन तब जनरेट होती है, जब जावा यूजर प्रोग्राम में कोई एप्लिकेशन क्लास को लोड करने की ट्राय करता है. लेकिन उस समय मे जरूरी क्लास नहीं मिलती है. जैसे, रिफ्लेक्शन को यूज़ करके या क्लास को डायनामिकली लोड करके, इसे ट्राय करना।

Example of ClassNotFoundException.

public class ClassNotFoundIllustration {

        public static void main(String[] args) {

            try {

                // here we use try block to Trying to load a non-existent class in program

                Class.forName(“com.nonexistent.Class”);

            } catch (ClassNotFoundException e) { // use a catch block

                System.out.println(“your searched Class is not found!”);

            }

        }

    }

Result – your searched Class is not found!

FileNotFoundException/CheckedException Java exception.

जावा प्रोग्राम में फाइलनॉटफाउंड एक्सेप्शन तब जनरेट होती है, जब जावा यूजर किसी प्रोग्राम में कोई ऐसी फ़ाइल ओपन करने की ट्राय करता है. जो मौजूद नहीं है, या जिसे मौजूदा प्रोग्राम में एक्सेस नहीं किया जा सकता है।

Java FileNotFoundException example.

import java.io.*;

    public class FileNotFoundExceptionIIllustration {

        public static void main(String[] args) {

            try {

                FileReader file = new FileReader(“notexistFile.txt”);

            } catch (FileNotFoundException e) {

                System.out.println(“your searched File is not found!”);

            }

        }

    }

Result – your searched File is not found!

IOException/Checked Exception Java exception.

जावा प्रोग्राम में आईओएक्सेप्शन इनपुट-आउटपुट से रिलेटेड कॉमन प्रोगाम इश्यूज जैसे, डाटा फ़ाइल रीड या राइट करने में फेलियर, सॉकेट से रीड करने में विफलता के लिए एक जनरल प्रोग्राम एक्सेप्शन टाइप है।

Example of an IOException Java exception.

import java.io.*;

    public class IOExceptionIllustration {

        public static void main(String[] args) {

            try {

                FileReader file = new FileReader(“sampleFile.txt”);

                file.read();

            } catch (IOException e) {

                System.out.println(“here file reading during IOException generate”);

            }

        }

    }

Result – here file reading during IOException occurred

IndexOutOfBoundsException/Unchecked Exception Java exception.

जावा प्रोग्राम में इंडेक्सआउटऑफ़एक्सेप्शन तब जनरेट होती है, जब जावा यूजर किसी लिस्ट या दूसरे कलेक्शन डाटा टाइप में कोई इनवैलिड इंडेक्स लोकेशन को एक्सेस करने की ट्राय करता है. जिसमे की इंडेक्स लोकेशन से जैसे, ArrayList का यूज़ किया जाता है।

IndexOutOfBoundsException example of a Java exception.

import java.util.*;

    public class IndexOutOfBoundsExceptionIllustration {

        public static void main(String[] args) {

            List<String> list = new ArrayList<>();

            list.add(“Macbook Pro”);

            list.add(“Asus Tuf”);

            list.add(“Hp Pavilion”);

            // here This will throw IndexOutOfBoundsException during program exception

            System.out.println(list.get(7));

        }

    }

Result – Exception in thread “main” java.lang.IndexOutOfBoundsException: Index 7 out of bounds for length 3

IllegalArgumentException/Unchecked Exception Java exception.

जावा प्रोग्राम में इललीगलआर्गुमेंटएक्सेप्शन तब जनरेट होती है, जब किसी यूजर डिफाइन क्लास मेथड को कोई ऐसा आर्गुमेंट डिटेक्ट होता है, जो नियम के अनुसार फाल्स या इललीगल नेचर का है।

Instance of IllegalArgumentException.

public class IllegalArgumentExceptionIllustration {

        public static void main(String[] args) {

            int value = -21;

            if (value < 0) {

                throw new IllegalArgumentException(“here you cannot set value as negative”);

            }

        }

    }

Result – Exception in thread “main” java.lang.IllegalArgumentException: here you cannot set value as negative

NumberFormatException/Unchecked Exception Java exception.

जावा प्रोग्राम में नंबरफॉर्मेटएक्सेप्शन तब जनरेट होती है, जब जावा यूजर द्वारा किसी स्ट्रिंग डाटा टाइप वैल्यू को नंबर डाटा टाइप में रिप्लेस करने की कोशिश की जाती है. जैसे, Integer.parseInt() फंक्शन मेथड को यूज़ करके और स्ट्रिंग डाटा टाइप के रूप में एक वैलिड नंबर नहीं है।

Instance of NumberFormatException.

public class NumberFormatExceptionIllustration {

        public static void main(String[] args) {

            String strtext = “Vcanhelpsu”;

            // here This will throw NumberFormatException during str to integer conversion

            int integer = Integer.parseInt(strtext);

        }

    }

Result – Exception in thread “main” java.lang.NumberFormatException: For input string: “Vcanhelpsu”

ConcurrentModificationException/Unchecked Exception Java exception.

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

Example of ConcurrentModificationException.

import java.util.*;

    public class ConcurrentModificationExceptionIllustration {

        public static void main(String[] args) {

            List<String> list = new ArrayList<>();

            list.add(“Java”);

            list.add(“Python”);

            list.add(“Ruby”);

            list.add(“Pearl”);

            for (String item : list) {

                if (item.equals(“Python”)) {

                    list.remove(item);  // here This will throw an ConcurrentModificationException program error

                }

            }

        }

    }

Result – Exception in thread “main” java.util.ConcurrentModificationException

NoSuchElementException/Unchecked Exception Java Exception.

जावा प्रोग्राम में नोसचएलिमेंटएक्सेप्शन तब जनरेट होती है, जब मौजूदा प्रोग्राम में किसी ऐसे एलिमेंट डाटा को एक्सेस करने की कोशिश की जाती है. जो की मौजूदा किसी कलेक्शन या लूप इटरेटर में मौजूद नहीं है. जैसे, जब इटरेटर में कोई एलिमेंट नहीं बचा हो तो next() फंक्शन को कॉल करना है।

NoSuchElementException example.

import java.util.*;

    public class NoSuchElementExceptionIllustration {

        public static void main(String[] args) {

            List<String> list = new ArrayList<>();

            list.add(“P”);

            list.add(“Q”);

           Iterator<String> iterator = list.iterator();

            // here it Moving to the past all arraylist elements

            iterator.next();

            iterator.next();

            // here This will throw NoSuchElementException program exception during run

            iterator.next();

        }

    }

Result – Exception in thread “main” java.util.NoSuchElementException

SecurityException/UncheckedException Java Exception.

जावा प्रोग्राम में सिक्योरिटीएक्सेप्शन तब जनरेट होती है, जब जावा लैंग्वेज में कोई सिक्योरिटी मैनेजर सिक्योरिटी रेस्ट्रिशन के आधार पर किसी जावा प्रोग्राम रिसोर्स जैसे, फ़ाइल या नेटवर्क रिसोर्स को यूजर एक्सेस से रिस्ट्रिक्ट कर देता है।

Example of SecurityException.

public class SecurityExceptionIllustration {

    public static void main(String[] args) {

        System.setSecurityManager(new SecurityManager());

        // here This will throw a SecurityException error, if security manager restrict any user permission

        System.exit(0);

    }

}

Result – Exception in thread “main” java.lang.UnsupportedOperationException: Setting a Security Manager is not supported

Leave a Reply