| |
GeekInterview.com > Interview Questions > J2EE > Core Java
| Print | |
Question: Exception Handling
Answer: What is the output of the following program, When tested under JDK 5.0
class ExceptionDemo { public static void main(String[] args) { int a[] = new int[] {1,2,3,4,5}; try{ System.out.prinltln(a[6]); } catch(Exception e) { System.out.println("Catching Exception ..."); } catch(ArrayIndexOutofBoundsException ae) { System.out.println("Catching ArrayIndexOutOfBounds Exception ..."); } } }
|
| June 06, 2008 02:31:59 |
#8 |
| r.praveenkumar |
Member Since: October 2007 Total Comments: 27 |
RE: Exception Handling |
| This will throw a compiler error while catching exceptions we should first catch child class exceptions and then only base class. The reason is if we follow this we will get the more specific reason for the failure ie what caused the exception to rise. |
| |
Back To Question | |