DemoException java
public class DemoException {
public void calculate(int i,int j) // throws Exception
{
System.out.println(i+j);
try {
System.out.println(i/j); // expect error can come
}
catch(Exception e)
{
// e.printStackTrace(); // system print error
//System.err.println("my error message"); // user error
// alternate
System.out.println("alternate code "+i/1);
}
finally {
System.out.println(i-j); // always execute
System.out.println(i*j);
}
}
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
DemoException d = new DemoException();
d.calculate(12, 2);
}
}
Comments