Page 170 - CITS - CSA - TP (Volume 2) - Hindi
P. 170

कं  ूटर सॉ वेयर ए ीके शन - CITS




           2  ArrayIndexOutOfBoundsException:
              •   िववरण: यह तब होता है जब ऐरे की सीमा के  बाहर इंडे  वाले ऐरे एिलम ट तक प ँचने का  यास िकया जाता है।
              •   ह डिलंग  ि कोण: सुिनि त कर  िक इंडे  ऐरे की सीमा के  भीतर है।

           public class ArrayIndexOutOfBoundsExceptionExample {
               public static void main(String[] args) {

                   try {
                       int[] arr = {1, 2, 3};
                       int element = arr[5]; // This will throw an ArrayIndexOutOfBoundsException
                       System.out.println(“Element at index 5: “ + element);

                   } catch (ArrayIndexOutOfBoundsException e) {
                       System.out.println(“Caught ArrayIndexOutOfBoundsException: “ + e.getMessage());

                   }
               }
           }

           आउटपुट:








           3  ArithmeticException:
              •   िववरण: तब होता है जब अंकगिणतीय ऑपरेशन के  प रणाम  प कोई अप रभािषत गिणतीय प रणाम  ा  होता है (उदाहरण के  िलए, शू
                 से भाग देना)।
              •   ह डिलंग  ि कोण: उन   ितयों की जाँच कर  जो अप रभािषत प रणामों की ओर ले जा सकती ह ।

           public class ArithmeticExceptionExample {
               public static void main(String[] args) {
                   try {

                       int result = 10 / 0; // This will throw an ArithmeticException
                       System.out.println(“Result of division: “ + result);

                   } catch (ArithmeticException e) {
                       System.out.println(“Caught ArithmeticException: “ + e.getMessage());
                   }
               }

           }
           आउटपुट:












                                                           156

                                  CITS : IT & ITES - कं  ूटर सॉ वेयर ए ीके शन - अ ास 106
   165   166   167   168   169   170   171   172   173   174   175