filmov
tv
Throw vs Throws in Java | Checked vs Unchecked Exception in Java | Java Interview Questions

Показать описание
Difference between Throw in Java and Throws in Java & Difference between Checked Exception and Unchecked Exception in Java is a very important Java Interview Question.
This video very clearly answers the above questions
What is throw in Java?
throw is a keyword in Java that is used while writing code to throw the exception.
What is throws in Java?
Throws is used to list down all the exceptions that a method might throw such that the code calling the method knows that these exceptions might occur hence suitable handling has to be done.
What are Checked Exceptions and Unchecked Exceptions in Java?
Checked Exceptions are the exception that must be handled by the code else you get compilation error or in other words all the exceptions for which compiler checks whether it is handled or not are called Checked Exceptions, hence it is mandatory to handle checked exception whereas Exceptions that are not checked by compiler whether they are handled or not are called Unchecked Exceptions.
Example of Checked Exceptions are ClassNotFoundException, IOException, SQLException.
Example of Unchecked Exception are ArithmeticException, NullPointerException etc.
This video very clearly answers the above questions
What is throw in Java?
throw is a keyword in Java that is used while writing code to throw the exception.
What is throws in Java?
Throws is used to list down all the exceptions that a method might throw such that the code calling the method knows that these exceptions might occur hence suitable handling has to be done.
What are Checked Exceptions and Unchecked Exceptions in Java?
Checked Exceptions are the exception that must be handled by the code else you get compilation error or in other words all the exceptions for which compiler checks whether it is handled or not are called Checked Exceptions, hence it is mandatory to handle checked exception whereas Exceptions that are not checked by compiler whether they are handled or not are called Unchecked Exceptions.
Example of Checked Exceptions are ClassNotFoundException, IOException, SQLException.
Example of Unchecked Exception are ArithmeticException, NullPointerException etc.