GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Tech FAQs  >  Programming  >  Java
Go To First  |  Previous Question  |  Next Question 
 Java  |  Question 854 of 928    Print  
throw and throws
what is the difference between throw and throws


  
Total Answers and Comments: 2 Last Update: March 24, 2008     Asked by: kulkarni85 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
March 24, 2008 06:20:54   #1  
ravi_1229 Member Since: November 2006   Contribution: 9    

RE: throw and throws
if user program explicitly wants to throw an exception(inbuilt or userdefined) then throw keyword is used.
if the user program wants to throw an exception in a particular condition then throw
keyword is used
metho(){
...........................
if(age>100){
new AgeBarException();
}else{
<write code>
}
}

if the user dont want to handle the exceptions he can throws the exceptions using

public void myMethod() throws Exception{
vector.add("9099");
}
the above method throws an exception which is not handled .

if another user uses the myMethod he have to handle that exception using try....catch...block
:)

 
Is this answer useful? Yes | No
March 24, 2008 06:22:55   #2  
ravi_1229 Member Since: November 2006   Contribution: 9    

RE: throw and throws
if user program explicitly wants to throw an exception(inbuilt or userdefined) then throw keyword is used.
if the user program wants to throw an exception in a particular condition then throw
keyword is used
metho(){
...........................
if(age>100){
throw new AgeBarException();
}else{
<write code>
}
}

if the user dont want to handle the exceptions he can throws the exceptions using

public void myMethod() throws Exception{
vector.add("9099");
}
the above method throws an exception which is not handled .

if another user uses the myMethod he have to handle that exception using try....catch...block
:)

 
Is this answer useful? Yes | No

 Related Questions

Latest Answer : throw is used to explicitly thorw some exception throws is used to tell the compiler the this method might through mentioned type of exception. ...

Latest Answer : If a method is not Handling a checked exception and wants the exception to be propagated to the caller of the method then that exception is declared in the Throws clause of its method prototype.Regards,Chandana.                                                                                                                                                                           ...

Which of the following is true?1) wait(),notify(),notifyall() are defined as final & can be called only from with in a synchronized method2) Among wait(),notify(),notifyall() the wait() method only throws IOException3) wait(),notify(),notifyall() & sleep() are methods of object class
A) 1B) 2 & 3C) 1 & 2D) 1 2 & 3 

A) Throws 

Latest Answer : Throw is used to pass an exception up to the method that called itThrows is used to indicate that method pass exception to the method that the method called ...
Read Answers (3) | Asked by : parth

Latest Answer : throw enables ur program  to throw an exception explicitily.general form is     throw  abcabc is an object of type Throwable or subclass of Throwable.throws : if a method is capable of causing an exception that it doesnot ...
Read Answers (2) | Asked by : Mahendran

1.throw Vs. throws clause?2.Use of EJBs?3.Design Patterns avail in Java?4.Different ways of achieving Exceptions in Java?5.Can we handle Run Time Exceptions?6.How to overcome OutOfMemoryError?7.CompileTime 
Latest Answer : 4.Whats the use of Marker Interfaces in java eventhough there r no methods in the Marker interfaces?Answer :     The marker methods specifies the functionality of a class depending upon the need. For example if a method needs to be serialised ...

View Question | Asked by : Manish

ServletException,IOException. 
View Question | Asked by : sujatham

what is the difference between throw and throws 
Latest Answer : if user program explicitly wants to throw an exception(inbuilt or userdefined) then throw keyword is used. if the user program wants to throw an exception in a particular condition then throw   keyword is used metho(){ ........................... ...


 Sponsored Links

 
Related Articles

Service Oriented Java Business Integration Review

Service Oriented Java Business Integration Review Introduction If you ve read through the texts which give you an introduction to SOA or Web Services you will often find them to be quite frustrating and the reason for this is because they spend too much time referencing business processes which are
 

Concepts of Object-Oriented Programming

Object Oriented JavaScript In this chapter you ll learn about OOP Object Oriented Programming and how it relates to JavaScript As an ASP NET developer you probably have some experience working with objects and you may even be familiar with concepts such as inheritance However unless you re already a
 

Java and Client Server Models

Java and Client Server Models The Role of Client Servers on the Web Client server models provide the essential mechanisms for working with the Internet In fact most of the World Wide Web is built according to this paradigm In client server models the web browsers run by millions of users are the cli
 

SQL Programming

SQL Programming Overview Anybody who has done something for a long time has probably wanted to change how things work at some point or another. A worker at a mill might have found a more efficient way of cutting logs, or a mathematics teacher might have had a hand in changing a school&rsquo;s al
 

WinRunner Programming Concepts

If you want to create WinRunner scripts that are highly efficient, there are important programming concepts that you will want to become familiar with. Understanding these concepts will provide you with a large number of key benefits. In addition to understanding these concepts, you must also learn
 

Programming Languages Certification

IT Certification programs have several options that will offer you the best knowledge.&nbsp; By learning everything that you need to know about information technology you will be able to open new doors to your career and personal business desires.&nbsp; IT Certification offers several vari
 

Using UML with Java

Using UML with Java While Java is not a new language its application for the development of embedded systems is quite new Developers are beginning to take a second look at modeling languages such as UML and many feel it can be a powerful tool in their development arsenal mosgoogle center Introductio
 

Neuro-linguistic Programming Methods

Neuro linguistic Programming Methods There are several methods used for performing Neuro linguistic Programming on an individual for obtaining insights into the psyche of the person in order to correct to modify certain patterns of behavior These techniques are also used for Neuro linguistic trainin
 

The Difficult Past of Neuro-linguistic programming

The Difficult Past of Neuro linguistic programming Neuro linguistic programming has had a rocky past with a number of lawsuits rivalry unsystematic development and intermittent progress During the 1980s the two founders separated after the lawsuit filed by Bandler Bandler went on to file several law
 

History of Neuro Linguistic Programming (NLP)

History of Neuro linguistic programming Neuro Linguistic Programming NLP is a system co founded by John Grinder and Richard Bandler for bringing about personal development in any individual by interpreting and translating the human perception experience beliefs and language It was developed in early
 

About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape