Question
Which of the following correctly handles multiple
exceptions in Java?Solution
In Java, a single try block can handle multiple exceptions by attaching multiple catch blocks. Each catch block specifies a distinct exception type. The exception hierarchy determines the order of catch blocks—child exceptions must precede parent exceptions. Example: try { int a = 5 / 0; // ArithmeticException int[] arr = new int[2]; System.out.println(arr[3]); // ArrayIndexOutOfBoundsException } catch (ArithmeticException e) { System.out.println("Arithmetic Exception caught"); } catch (ArrayIndexOutOfBoundsException e) { System.out.println("Array Index Out of Bounds Exception caught"); } catch (Exception e) { System.out.println("Generic Exception caught"); } ________________________________________ Why Other Options Are Incorrect: 1. Separate try blocks for each exception: This is inefficient and makes code less readable. A single try block with multiple catch blocks is the recommended approach. 2. Nesting try blocks within each other: This is not a standard practice unless the logic explicitly demands it. It can lead to convoluted and hard-to-maintain code. 3. Single catch block for all exceptions: While possible, this is a poor practice as it does not differentiate exception types, leading to less precise error handling. 4. Writing the exception type as a string: Java’s catch block requires exception classes, not strings, for type checking.
Which of the following is not a benefit of seed hardening?
In which year was the “Krishi Vigyan Kendra” (KVK) programme launched by ICAR?
Legume crops includes
(A) Pigeon pea
(B) Greengram
(C) Lentil
(D) Horsegram
(E) Rapeseed
Choose the correct answer from the options given below:
Excess copper induces deficiency of which mineral in plants ?
Which of following group of plant nutrients is as structural elements?
Study and selection, planting, care and removal of individual trees, shrubs, vines and other perennial woody plants is known as
Which of the following is considered as power house of the cell?
Which initiative offers open-source infrastructure, including farmer, village map, and crop sown registries, to create farmer-centric solutions?
Leaf curl disease of cotton is due to
Central Institute of Arid Horticulture was located at