ALLInterview.com :: Home Page KalAajKal.com
 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                      
info       Did you received any Funny E-Mails from your Friends and like to share with rest of our friends? Yeah!! you can post that stuff   HERE
Google
 
Categories  >>  Software  >>  Core Java  >>  Java J2EE  >>  Java Related
 
 


 

 
 Core Java interview questions  Core Java Interview Questions
 Advanced Java interview questions  Advanced Java Interview Questions
 Swing interview questions  Swing Interview Questions
 EJB interview questions  EJB Interview Questions
 Servlets interview questions  Servlets Interview Questions
 Struts interview questions  Struts Interview Questions
 JDBC interview questions  JDBC Interview Questions
 JMS interview questions  JMS Interview Questions
 SunOne interview questions  SunOne Interview Questions
 J2EE interview questions  J2EE Interview Questions
 Weblogic interview questions  Weblogic Interview Questions
 Websphere interview questions  Websphere Interview Questions
 Java Networking interview questions  Java Networking Interview Questions
 Java J2EE AllOther interview questions  Java J2EE AllOther Interview Questions
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 ?    41 Yes 6 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 ?    25 Yes 7 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 ?    9 Yes 2 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 ?    1 Yes 5 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 ?    2 Yes 5 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 ?    3 Yes 0 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 ?    8 Yes 2 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 ?    3 Yes 1 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 ?    5 Yes 0 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 ?    4 Yes 0 No
Chandra Sekhar
 
  Re: what is difference between throw and throws in exception?
Answer
# 11
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 ?    0 Yes 4 No
Clement
 
  Re: what is difference between throw and throws in exception?
Answer
# 12
throw : throw is used to throw user defined exceptions.
        For ex: MyException written by user.it may be either
        checked or unchecked exception.

throws: throws is used to throw exception those are handled by
         JVM directly.
         throws is used in method declaration to 
         intimate user that, it throw the exception that must 
         be handled by calling method.

Note :use throws when your method does not handle exception.
 
Is This Answer Correct ?    1 Yes 0 No
Raju
 
  Re: what is difference between throw and throws in exception?
Answer
# 13
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 ?    2 Yes 0 No
Raju
 
  Re: what is difference between throw and throws in exception?
Answer
# 14
throw - It is used to throw an Exception.
throws - This is used to specifies that the method can 
throw Exception
 
Is This Answer Correct ?    1 Yes 0 No
Prasanna
 
  Re: what is difference between throw and throws in exception?
Answer
# 15
throws is used for throwing an exception from a method to 
jvm, the jvm should handle it.where us throw is used when 
user needs to raise his own exception.
 
Is This Answer Correct ?    0 Yes 0 No
Lokesh
 
  Re: what is difference between throw and throws in exception?
Answer
# 16
throw: It is used to explicitly or manually throw an 
exception.it can throw user defined exceptions.

throws:It tells that exception to b handled by calling 
function. It tells caller that what exception that method 
could throw.
 
Is This Answer Correct ?    2 Yes 0 No
Manu
 

 
 
 
Other Core Java Interview Questions
 
  Question Asked @ Answers
 
can we write a program with out a class in core java? Wipro5
diff b/w sleep(1000) and wait(1000)? Huawei2
What is the purpose of the File class?  2
What is light weight component?  3
what is the difference between equals method and == Professional-Access11
how to compile jsp? Logica-CMG3
We have two methods to create methods the threads. 1. Implementing runnable interface 2. Extending to thread class and overriding run method. Among these two which one is better and why? Please explain me in detail.  2
Describe inheritance as applied to java?  4
Which method is used to find that the object is exited or not?  1
int a=10,b=20,c=30 a= b+c;b=a+c;c=a+b; System.out.println("The value is"+a+b+c; Honeywell16
what is tempplate pattern RBS4
What is the Vector class?  3
which swing component is similar to rich text box in .net/vb  1
Explain, why the constructor is required in implemented class?  2
Hey buddy.. can you please tell me about the use of marker interface? And is there any link between marker interface and factory methods? Thanks in advance.  2
what ide u r using and wat version, how wil u build the project etc ?  2
Why would you desing a J2EE application so user data is entered by way of a JSP page and managed by an underlying Java Beans class? Adobe3
1).Is Object class abstract or not? 2).Is main method(public static void main(String args[])low priority thread or high priority thread? TCS2
What is an Exception ?  6
What is the difference between getCodeBase and getDocumentBase methods?  1
 
For more Core Java Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com