Continue with your mobile number
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.
निम्नलिखित में से कौन-सा सही सुमेलित युग्म नहीं है ?
प्रशासन/विधि के संदर्भ में 'covenant' शब्द का उपयुक्त हिंदी पर्य...
अशुद्ध वर्तनी वाला शब्द है
भारोपीय परिवार में निम्नलिखित में से कौन-सी भाषा शामिल नह...
सूची I को सूची II से सुमेलित कीजिए और सूचियों के नीचे दिए गए क...
निम्नलिखित युग्मों में से कौन-सा सही सुमेलित युग्म नहीं ह...
इला चंद्र जोशी द्वारा रचित, सन्यासी की विधा क्या है ?
निम्नलिखित प्रत्येक प्रश्न में दी गई रचना के रचयिता के ना...
निम्नलिखित मूल अंग्रेज़ी वाक्य और इसके हिंदी में अनूदित ...
निम्नलिखित में से कौन-सा मशीन साधित अनुवाद प्रणाली नहीं है?