ALLInterview.com :: 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                      
Google
   
 
Categories >> Software >> Java Related >> Java J2EE >> Core Java
 
 


 

 
 Core Java interview questions  Core Java Interview Questions (1720)
 Advanced Java interview questions  Advanced Java Interview Questions (331)
 Swing interview questions  Swing Interview Questions (43)
 EJB interview questions  EJB Interview Questions (134)
 Servlets interview questions  Servlets Interview Questions (255)
 Struts interview questions  Struts Interview Questions (195)
 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 (145)
 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)
Question
what is difference between throw and throws in exception?
 Question Submitted By :: Guest
I also faced this Question!!     Rank Answer Posted By  
 
  Re: what is difference between throw and throws in exception?
Answer
# 1
"throw" is used to handle user-defined exception.
JVM handles the exceptions which are specified by "throws"
 
Is This Answer Correct ?    257 Yes 50 No
Neema
 
  Re: what is difference between throw and throws in exception?
Answer
# 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 ?    120 Yes 76 No
Pavithra
 
 
 
  Re: what is difference between throw and throws in exception?
Answer
# 3
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 ?    40 Yes 29 No
Shiva
 
  Re: what is difference between throw and throws in exception?
Answer
# 4
hi pavitra u r nswer is wrong 
Is This Answer Correct ?    63 Yes 23 No
Shiva
 
  Re: what is difference between throw and throws in exception?
Answer
# 5
throw will throws the exception,
and throws declares that the function will throw an exception
you should catch all every functions throwing and exception
u declare it or catch it
 
Is This Answer Correct ?    28 Yes 25 No
Chirag
 
  Re: what is difference between throw and throws in exception?
Answer
# 6
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
Srinath
 
  Re: what is difference between throw and throws in exception?
Answer
# 7
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
{
try
{
}
catch(Exception exe)
{
// catch all the exceptions and provide some meaningful
message
throw BusinessException("An error occured while
trying to connect to DB");
}

}
 
Is This Answer Correct ?    43 Yes 12 No
Raj
 
  Re: what is difference between throw and throws in exception?
Answer
# 8
throws:
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
errors.

throw:
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
 
  Re: what is difference between throw and throws in exception?
Answer
# 9
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
Velayutham
 
  Re: what is difference between throw and throws in exception?
Answer
# 10
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
 

 
 
 
Other Core Java Interview Questions
 
  Question Asked @ Answers
 
Hai all I want to print given array in reverse order Ex: int a[]={1,2,3,4,5};display this array in reverse order.   4
I need some details about an employee. i have only the employee id in my presentation layer(JSP).I entered that ID and click "Show Details" Button. Question is how the JSP pass that id to Controller layer and DAO and what mechanism we are using to retrive data from DB and how the data passed to JSP as a Output. Please explain in detail. TCS 1
how exactly garbage collection take place?   4
How to excute - Interface - Inner class- method can any one tell how to execute/ call this main method public interface abc { static int i=0; void dd(); class a1 { a1() { int j; System.out.println("inside"); }; public static void main(String a1[]) { System.out.println("in interfia"); } } }   1
how to transactions(Bank transactions) in business process in ejb? Photon 1
Can a class inherit the constructors of its superclass? Wipro 9
what is inner class? HCL 6
What is advantage of using threads? BMC 2
What is map and hashmap? also tell the difference.   1
why top level class could not be static L&T 2
how to handled exceptions & erros in ejb? Satyam 1
wht is mean by dirty read?   1
 
For more Core Java Interview Questions Click Here 
 
 
 
 
 


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

ALLInterview.com   ::  KalAajKal.com