Saturday, May 30, 2015

Exception Check/Uncheck

import java.io.IOException;

// CHECK EXCEPTION: It compelled us to surround with try/catch block or throws an exception
// UNCHECK EXCEPTION: It don't compelled us to surround with try/catch block or throws an exception

public class Class1 {

private void abc() throws IOException {
System.out.println("3");
//throw new ArithmeticException();      1 2 and 3 matra print bhyo

// case of IOException
// yedi try/catch use garyo bhana sap 1 2 3 4 5 print hunxa
// but throws use garyo bhana tyo line or method use garna sapai line or methods
// le throws or try/catch use garna parxa

throw new IOException();

}
private void xyz() {
System.out.println("2");
try {
this.abc();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("4");

}
public static void main(String[] args) {

Class1 c1 = new Class1();
System.out.println("1");
c1.xyz();
System.out.println("5");
}
}


No comments:

Post a Comment