Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


what is difference between throw and throws in exception?

Answers were Sorted based on User's Feedback



what is difference between throw and throws in exception?..

Answer / ravivarman

Throw keyword can be used by a program to throw exceptions
explicitly.the execution of the current block stops
immediately after the throw statement.
A method should declare that it can cause an exception and
expects its caller handle or re-throw the exception.

Is This Answer Correct ?    0 Yes 0 No

what is difference between throw and throws in exception?..

Answer / basant

) throws keyword gives a method flexibility of throwing an Exception rather than handling it. with throws keyword in method
signature a method suggesting its caller to prepare for Exception declared in throws clause, specially in case of checked Exception and provide sufficient handling of them. On the other hand throw keyword transfer control of execution to caller by throwing an instance of Exception. throw keyword can also be used in place of return as shown in below example:

private static boolean shutdown() {
throw new UnsupportedOperationException("Not yet implemented");
}

as in below method shutdown should return boolean but having throw in place compiler understand that this method will always throw exception .


Read more: http://javarevisited.blogspot.com/2012/02/difference-between-throw-and-throws-in.html#ixzz1xaAnuuuu

Is This Answer Correct ?    0 Yes 0 No

what is difference between throw and throws in exception?..

Answer / sakariya vikram

through is user defind exception this is created by user and
throughs is a jvm(system) defined exception.

Is This Answer Correct ?    1 Yes 1 No

what is difference between throw and throws in exception?..

Answer / deewan singh

throw keyword is used to throw Exception from any method or static block in Java while throws keyword, used in method declaration, denoted which Exception can possible be thrown by this method.

Is This Answer Correct ?    0 Yes 0 No

what is difference between throw and throws in exception?..

Answer / chandrakala

throw and throws are clauses.
throws: if we are not interested to catch the exception then we have to use throws. if any exception arises then internally JVM handles that exception.
throw: If we want to throw an exception explicitly we have to use throw.It comes under user defined exception.

Is This Answer Correct ?    0 Yes 0 No

what is difference between throw and throws in exception?..

Answer / suman

"throw" is used to handle user-defined exception.
JVM handles the exceptions which are specified by "throws"

Is This Answer Correct ?    0 Yes 0 No

what is difference between throw and throws in exception?..

Answer / ravikumar

Throws - what ever the exception you are declaring are
taken care by JVM. If it is a user defined exception in throws
block, JVM doesn't know when to throw that exception . For
this purpose we use Throw for a certain conditions/logic to
throw these user defined exceptions

Is This Answer Correct ?    0 Yes 1 No

what is difference between throw and throws in exception?..

Answer / clement

throws specifies that a method could throw an exception
while throw is used to throw a particular type of exception

throw IOException;

public void clem()throws exception

Is This Answer Correct ?    1 Yes 7 No

Post New Answer

More Core Java Interview Questions

How is a variable stored in memory?

0 Answers  


What is methods and methodology?

0 Answers  


What is volatile keyword in java

0 Answers  


Urgent requirement of JAVA/.NET/QA in a CMMI level3 MNC for Pune location.

0 Answers  


what is the difference between String and StringBuffer classes?

2 Answers   Infosys,


Considering notepad/ie or any other thing as process, what will happen if you start notepad or ie 3 times? Where 3 processes are started or 3 threads are started?

0 Answers  


does core java and j2se both are same?

5 Answers  


Interface A { String test(); } Interface B { int test(); } Create a class AB which must implements both A & B interfaces.

17 Answers   Hewitt,


What is an exception?

6 Answers  


What will be the initial value of an object reference which is defined as an instance variable?

0 Answers  


What is the base class in java from which all classes are derived?

0 Answers  


Which is best ide for java?

0 Answers  


Categories