| Difference Between Throws & Throw 1. Throws clause used to declare an exception while Throw keyword used to throw an exception explicitly. 2. Throws is followed by exception class names while Throw is followed by an instance variable. 3.Throws clause is used with method name while Throw used inside method body to invoke an exception. 4. Example of Throw
try
{
throw new Exception("Something went
wrong!!");
}
catch(Exception
exp)
{
System.out.println("Error:
"+exp.getMessage());
}
Example of Throws:
public
void sample() throws ArithmeticException{
//Statements
} 5. By using Throw keyword in java you cannot throw more than one exception but using throws you can declare multiple exceptions.
For Example:
Throw:
throw
new ArithmeticException("An integer should not be divided by zero!!")
throw
new IOException("Connection failed!!")
Throws:
throws IOException, ArithmeticException, NullPointerException, ArrayIndexOutOfBoundsException
|
Computer Science :: 11th/12th, Computer Engineering :: Degree/Diploma, Coding Concept ( C, C++ & JAVA Programming, JDBC Concept, DBMS - SQL Concept, Data Structure, Communication & Network Concept.
THROW & THROWS
Subscribe to:
Posts (Atom)
Programmingway@Eklavya Technosys!: Class - 7 A or B | Computer | 100 Questions!
Programmingway@Eklavya Technosys!: Class - 7 A or B | Computer | 100 Questions! : 1) What is digital citizenship? 2) What is a digital citi...
-
COMPUTER TERMINOLOGY 1) TCP/IP - Transmission Control Protocol/ Internet Protocol. 2) HTTP...
-
https://makecode.com/_3VxaMo6c3YPp Code 1) What is Make Code Arcade? Answer: Make Code Arcade is a Block based coding. 2) Writ...
-
1) Choose correct one :- 1) The step by step plan of solution for solving a problem is called ____. a) Algorithm b) Internet c) URL d) M...
-
1) ___ is the response of the receiver after perceiving the message. a) Encoding b) Decoding c) Channel d) Feedback 2) Which of the fo...
-
Check whether the number is negative or positive after taking a number as input from the user. TextWindow . WriteLine ( "Ente...
No comments:
Post a Comment