83 What is exception chaining in Java?

Code:




import java.io.IOException;

public class Test {

static void m1() throws Throwable
  {
try
{
System.out.println(" Try Block ");
int a = 10/0;
}
catch(Exception e)
{
System.out.println(" Catch Block ");
throw e.initCause(new IOException("we are unable to hold and read and write infinity values"));
}
}

public static void main(String args[])
{
try
{
System.out.println(" Main Method ");
m1();
}
catch( Throwable t )
{
System.out.println(t.getCause());
}
}
}




Output:


Previous
Next Post »