Answer to Question #230267 in Java | JSP | JSF for kodwros

Question #230267

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.


1
Expert's answer
2021-08-30T01:35:53-0400

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");  
      }    
	}
}





Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS