|
| ||||||||||
| Tags: exception handling, java, sun, throw, throws |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| Difference between throw and throws in Java Exception Handling
|
|
#2
| ||||
| ||||
| 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 10:38 PM. |
|
#3
| ||||
| ||||
| 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");
}
.
.
.
}
__________________ Grand Theft Auto 4 PC Video Game |
|
#4
| ||||
| ||||
| 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. |
![]() |
|
| Thread Tools | Search this Thread |
| |
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 03:38 AM |
| Exception handling in EJB | KennedII | Software Development | 5 | 25-02-2010 03:40 AM |
| Java : Difference between the Checked and Unchecked Exception | Rajeev D | Software Development | 4 | 08-02-2010 05:17 PM |
| Svchost.exe Throws Exception in Windows xp | KomalUpadhyay | Operating Systems | 3 | 11-12-2009 12:07 AM |
| How to throw a custom exception in .NET? | Paramartha | Software Development | 3 | 11-09-2009 11:18 AM |