Sunday 8 February 2015

Try And Finally Without Catch Block

1. We Can Use Finally after try block ,it will run gives message in finally block.But can not handle exception.
Syntax:

try{


}Finally{


}

public class ExceptionSample {
public static void main(String[] args) {
try {
int i=10/0;
}finally{
System.out.println("Finally Block");
}
System.out.println("You Are Come Back In Main");
}

}

Output:
Exception in thread "main" Finally Block
java.lang.ArithmeticException: / by zero
at exception_handling.ExceptionSample.main(ExceptionSample.java:6)

No comments:

Post a Comment