throw is used to explicitly throw an exception. Wherever you want that exception occurs you can use throw. throws is used with method signature. If in a method there occurs an exception you can provide throws with method signature which gives the user idea that there may occur an exception in this method. | 0 |
By: [email protected] On: Thu Jan 09 10:52:06 IST 2014 0 359 0 | 359 |
Are You Satisfied :6Yes4No |
1.Throws clause in used to declare an exception and thorw keyword is used to throw an exception explicitly. 2. If we see syntax wise than throw is followed by an instance variable and throws is followed by exception class names. 3. The keyword throw is used inside method body to invoke an exception and throws clause is used in method declaration (signature). 4.throws keyword cannot be used anywhere exception method signature while throw keyword can be used inside method. | 0 |
By: [email protected] On: Thu Jan 09 12:54:39 IST 2014 0 392 0 | 392 |
Are You Satisfied :3Yes2No |
Hi Could you please provide the code for this.it's really helpful, | 0 |
By: [email protected] On: Thu Jan 09 15:00:06 IST 2014 5 0 2 | 7 |
Are You Satisfied :1Yes1No |
Thanks for all your replies.We can handle the exception or simply throw the exception by using throws. What my question is how to decide we have to use throw or throws? this is the question asked in one of my interview. | 0 |
By: [email protected] On: Thu Jan 09 23:14:38 IST 2014 3 0 0 | 3 |
Are You Satisfied :1Yes1No |
You use throws in a method signature to indicate that a method is capable of throwing a particular exception. Any code calling this method will have to deal with the possibility that that particular exception can occur. The throw keyword is used to actually throw an exception. It can be used wherever you can place a statement. | 0 |
By: [email protected] On: Fri Jan 10 11:50:12 IST 2014 0 9 0 | 9 |
Are You Satisfied :0Yes0No |
if the method throws IOException or some other exception, how to decide whether to use throws or throw For eg, public void readFile() throws IOException{ } or public void readFile(){ throw new IOException() } how to decide? | 0 |
By: [email protected] On: Fri Jan 10 23:28:48 IST 2014 3 0 0 | 3 |
Are You Satisfied :0Yes0No |
Suppose i have developed one code ,and you want to take my code and use in your program ,then please tell me how u will u know that my code is going to generate an exception.So by declaring throws in my method u can conform that someones code is going to generate exception.So in next step u will Handel the exception. Using Throw keyword u can throw exception manually.Suppose u have developed pension program in that program u r passing invalid age.At that time you have to throw exception is "U Hav entered Invalid Age ".... I hope u Got me... Pravat Kumar Swain [email protected] | 0 |
By: [email protected] On: Wed Jan 15 09:11:00 IST 2014 -3 0 0 | -3 |
Are You Satisfied :1Yes1No |