What is the difference between throw and throws?

Answers were Sorted based on User's Feedback



What is the difference between throw and throws?..

Answer / balaji

throw:it is used to raise exception explicitly
that means it is use when a user defined exception is raised

throws:if a method is capable of throwing an exception but
it does not handle the exception that must be specified by
using "throws" class

Is This Answer Correct ?    23 Yes 1 No

What is the difference between throw and throws?..

Answer / rakesh nath

Throw clause is used in any part of the code where you want
to throw any specific exception to the calling method while
throws can be termed as a substitute for try-catch block.

When an exception occurs in a program, the compiler needs to
know what should be done with that exception. For that
either we should have a try-catch block or the method should
have the throws clause attached, as follows.

<access-modifier> <return-type> myMethod(<parameter-list>)
throws <exception-list>

for example, public void meth1() throws MyException

throw can handle only ONE throwable object while throws can
handle multiple throwable objects seperated by commas.

Is This Answer Correct ?    13 Yes 1 No

What is the difference between throw and throws?..

Answer / suresh

mainly throw is used for user defined exceptions and throws
is used for compiler defined excetions.
Ex: if u get a NullPointer exception then we throws this
excetion to the compiler defined excetion class.

if u get malformed or ur own excetion in this time we to
throw this to our own defined excetion

Is This Answer Correct ?    2 Yes 1 No

What is the difference between throw and throws?..

Answer / manish kushwaha

First of all i would say both are reserved keyword in java

In Java Exception handling we are using above keyword throw
and throws.

Difference:
throws: throws clause is always use to propagate method
level exception, when ever you will use this clause, caller
method responsibility is to handle exception trowed by the
same method.

throw: this is the clause use to throw the instance of that
exception, main use of this throw clause is in user define
exception use you have written your own exception when ever
this exception will come you will throw this exception object.

Is This Answer Correct ?    1 Yes 1 No

What is the difference between throw and throws?..

Answer / surender kannuri

throws clause is used to whenever programmer doesn't want to
handle exception.throws it out of method.

throw is used whenever programmer wants to handle exception
explicitly by using catch blocks.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Core Java Interview Questions

Which are thin and thicK wrapper Class's in Java?

1 Answers  


Hi Every One I Have Small Doubt Please answer This???????????????????????????? I Want to use AbstractList class methods(java.util.AbstractList) My Program is import java.util.*; class DemoOne extends AbstractList { public static void main(String[] args) { AbstractList a=new DemoOne();//This One is Correct?? DemoOne a1=new DemoOne();//This One is Correct?? Both Are Not Working System.out.println("Hello World!"+a); System.out.println("Hello World!"+a1); } } Error IS: DemoOne.java:2: DemoOne is not abstract and does not override abstract method get(int) in java.util.AbstractList class DemoOne extends AbstractList AnyOne can Please Provide The Solution????????????????????????? Plzzzzzzz

3 Answers  


Can we extend a class with private constructor?

0 Answers  


What is the purpose of methodology?

0 Answers  


What are the special characters?

0 Answers  






What are the latest versions in JAVA related areas?

3 Answers   Netcraft,


What are library required to connect to excel sheet.

2 Answers   Cap Gemini,


Can we create object of static class?

0 Answers  


In which language JVM (Java Virtual Machine) is implemented

5 Answers  


What is java string pool?

0 Answers  


Explain runtime exceptions?

0 Answers  


Can u overload main()method.Give with example.

6 Answers   IBM, Schimatic Technologies,


Categories