:: Home Page            
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
Categories >> Software >> Java Related >> Java J2EE >> Core Java


 Core Java interview questions  Core Java Interview Questions (1728)
 Advanced Java interview questions  Advanced Java Interview Questions (332)
 Swing interview questions  Swing Interview Questions (44)
 EJB interview questions  EJB Interview Questions (134)
 Servlets interview questions  Servlets Interview Questions (255)
 Struts interview questions  Struts Interview Questions (196)
 JDBC interview questions  JDBC Interview Questions (187)
 JMS interview questions  JMS Interview Questions (9)
 SunOne interview questions  SunOne Interview Questions (3)
 J2EE interview questions  J2EE Interview Questions (71)
 Weblogic interview questions  Weblogic Interview Questions (147)
 Websphere interview questions  Websphere Interview Questions (14)
 Java Networking interview questions  Java Networking Interview Questions (20)
 Java J2EE AllOther interview questions  Java J2EE AllOther Interview Questions (87)
what is difference between throw and throws in exception?
 Question Submitted By :: Core-Java
I also faced this Question!!     Answer Posted By  
# 1
"throw" is used to handle user-defined exception.
JVM handles the exceptions which are specified by "throws"
Is This Answer Correct ?    261 Yes 50 No
# 2
throws is used to throw an exception from the method
without handling that exception where as 'throw' is used
to throw the exception to catch block and handle it.
Is This Answer Correct ?    123 Yes 78 No
# 3
hi pavitra u r nswer is wrong 
Is This Answer Correct ?    64 Yes 23 No
# 4
In Throws, what ever the exception you are declaring are
handle 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.

I think the above makes sense.
Is This Answer Correct ?    45 Yes 5 No
Chandra Sekhar
# 5
Method capable of raising an exception but not handling the
same. i.e to say no Try Catch block is implemented in the
Method, to handle the exception.
The callers should create the Try Catch Block to safeguard
against the exception.
If the above is not followed it would result in Compilation

The method that raises the exception also handles the same
in its Catch block.
If unhandled the exception can also be handles by the
Callers Try Catch Block.
Hope this makes sense.
Is This Answer Correct ?    44 Yes 10 No
Anu Mathew
# 6
throws --> throws declare that it throws the exception to
the calling method.

throw --> it is surrounded by the try catch block actually
it does the work, of throwing the exception.

For Example:

public void testMethod() throws BusinessException
catch(Exception exe)
// catch all the exceptions and provide some meaningful
throw BusinessException("An error occured while
trying to connect to DB");

Is This Answer Correct ?    43 Yes 13 No
# 7
throws keyword is used 2 delegate the responsibility of
exception handling 2 caller method where as throw keyword
used 2 hand over the creted customised excetion object 2
jvm 2 handle the excepion.
Is This Answer Correct ?    33 Yes 7 No
# 8
throw- means user defined exception. we want throw manually
throw the exception.
throws- means jvm going to take all exception.
Is This Answer Correct ?    33 Yes 10 No
# 9
throw is used for to through exception system explicitly,and
throws is u sed for to throws exception means throws
ioexception and servletexception and etc.........
Is This Answer Correct ?    41 Yes 29 No
# 10
throw : throw is used to throw exception by user whenever he
feels to throw exceptions. throw is used to throw
either user defined or runtime exception.
for ex : throw new MyException(), here MyException
is user written exception.
throw new NullPointerException(), here
NullPointerException is RuntimeException.

throws: throws is used by the method to throw exception to
the calling method. And method itself does not able
to handle it so it throws to calling method.
Is This Answer Correct ?    10 Yes 0 No

Other Core Java Interview Questions
  Question Asked @ Answers
What is the use of static keyword in "public static void main()" Infosys 10
84. try { 85. ResourceConnection con = resourceFactory.getConnection(); 86. Results r = con.query(”GET INFO FROM CUSTOMER”); 87. info = r.getData(); 88. con.close(); 89. } catch (ResourceException re) { 90. errorLog.write(re.getMessage()); 91. } 92. return info; Which is true if a ResourceException is thrown on line 86? 1 Line 92 will not execute. 2 The connection will not be retrieved in line 85. 3 The resource connection will not be closed on line 88. 4 The enclosing method will throw an exception to its caller.   1
I have a Arraylist object, it has duplecate values also. Now question is i want delete duplecate data in that objet with out using Set? Aricent 8
what is difference between validation.xml & validation rules.xml? BirlaSoft 8
why java does not have operator overloading?   2
how cani read a command line argument?(usingfile object).   3
What is the exact difference in between Unicast and Multicast object ? Accenture 4
What classes of exceptions, thrown by a throw statement?   2
what is Vector class?   2
What is the Set interface?   2
please write java program of instanceOf keyword implementation TCS 1
What are the ways of polymorphism other than Overridding & Overloading   1
For more Core Java Interview Questions Click Here 

Copyright Policy  |  Terms of Service  |  Articles  |  Site Map  |  RSS Site Map  |  Contact Us
Copyright © 2013  All Rights Reserved.   ::