Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Difference between throw and throws in Java Exception Handling

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 09-11-2009
Member
 
Join Date: Sep 2009
Posts: 177
Difference between throw and throws in Java Exception Handling
  

I am learning Java. I reached the topic of exception handling in Java. I am not able to understand the exact difference between throw and throws with respect to exception handling in Java. What is the actual difference between the two ? What are the funtionality of each individual ? I am totally lost in this topic.

Reply With Quote
  #2  
Old 09-11-2009
Member
 
Join Date: Jan 2008
Posts: 1,515
Re: Difference between throw and throws in Java Exception Handling

The keyword throw and throws are used for Exception handling in Java. Sun Microsystems developed Java has many feature of which is Exception Handling. Precisely a throw statement initiates an exception to be thrown, where as the throws clause declares that the method is expected to throw one or more checked execptions. Thus both are different and perform two different task.

Last edited by Modifier : 09-11-2009 at 11:38 PM.
Reply With Quote
  #3  
Old 09-11-2009
Member
 
Join Date: Oct 2005
Posts: 2,389
Re: Difference between throw and throws in Java Exception Handling

In very simple words, "throws" declares that the method is capable of throwing an exception while "throw" actually does the job of throwing the exception. They are not same.
eg:
Code:
public void Exep(int param) throws MyException
{

if (param > 7)
{
throw new MyException("You have entered big value");
}
.
.
.
}
Consider the above code. The keyword throws signifies that the method MyException is expected to throw exception and the keyword throw will actually throw the exception.
Reply With Quote
  #4  
Old 09-11-2009
Member
 
Join Date: Apr 2008
Posts: 1,948
Re: Difference between throw and throws in Java Exception Handling

The keyword throw in Java is used to raise exception explicitly that means it is used when a user defined exception is raised.
The keyword throws in Java is a modifier of a method that is expected to generate and throw exception/s. Mostly methods which are capable of throwing an exception but not handling are specified with throws keyword.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Difference between throw and throws in Java Exception Handling"
Thread Thread Starter Forum Replies Last Post
AxAcroPDF throws unhandled exception on click of TAB Who is it Windows Software 5 14-07-2010 04:38 AM
Exception handling in PL/SQL Ameeryan Software Development 5 25-02-2010 11:04 PM
Java : Difference between the Checked and Unchecked Exception Rajeev D Software Development 4 08-02-2010 06:17 PM
Svchost.exe Throws Exception in Windows xp KomalUpadhyay Operating Systems 3 11-12-2009 01:07 AM
How to throw a custom exception in .NET? Paramartha Software Development 3 11-09-2009 12:18 PM


All times are GMT +5.5. The time now is 03:07 AM.