Sunday, 19 May 2013
Exception - 7 -
package net.dharmaraj;
public class A
{
private void method1() throws Exception
{
throw new RuntimeException();
}
public void method2()
{
try
{
method1();
}
catch (RuntimeException e)
{
System.out.println("Caught Runtime Exception");
}
catch (Exception e)
{
System.out.println("Caught Exception");
}
}
public static void main(String args[])
{
A a = new A();
a.method2();
}
}
The above lines of code -
1)will not compile.
2)will compile and show - "Caught Runtime Exception".
3)will compile and show - "Caught Exception".
4)will compile and show both the messages one after another in the order they appear.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment