What is difference between error and exception? In the case of exception handling, what is the need for finally block? Can finally block be used without catch? Explain your opinion with example.
a. The difference between error and exception is that error occurs at run time and are not know to the compiler while exception.
b. The finally block is used to execute important codes whether an exception occurs or not.
c. Yes. Finally block be used without catch.
e. Example
public class Main
{
public static void main(String[] args) {
try {
int x=12/0;
System.out.println(x);
}
finally {
System.out.println("finally block");
}
}
}
Comments
Leave a comment