Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


what is difference between throw and throws in exception?

Answers were Sorted based on User's Feedback



what is difference between throw and throws in exception?..

Answer / chirag

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 ?    29 Yes 25 No

what is difference between throw and throws in exception?..

Answer / manu

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 ?    4 Yes 0 No

what is difference between throw and throws in exception?..

Answer / sinduja

THROW IS USED TO THROW AN EXCEPTION EXPLICITLY WHEREAS,THROWS INCLUDED IN THE METHODS DECLARATION PART WITH A LIST OF EXCEPTION THAT IT CAN POSSIBLE TO THROW.

THROW IS USED TO PASS CUSTOMER MESSAGE.AND THROW HANDLES
USER DEFINE EXCEPTION.
WHEREAS THROWS IS HANDLED BY JVM.

Is This Answer Correct ?    4 Yes 0 No

what is difference between throw and throws in exception?..

Answer / raju

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 ?    4 Yes 1 No

what is difference between throw and throws in exception?..

Answer / prasanna

throw - It is used to throw an Exception.
throws - This is used to specifies that the method can
throw Exception

Is This Answer Correct ?    3 Yes 0 No

what is difference between throw and throws in exception?..

Answer / savita patil

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 ?    3 Yes 1 No

what is difference between throw and throws in exception?..

Answer / gourav shivhare

The throw keyword denotes a statement that causes an exception to be initiated. It takes the Exception object to be thrown as an argument. The exception will be caught by an enclosing try-catch block or propagated further up the calling hierarchy. The throws keyword is a modifier of a method that denotes that an exception may be thrown by the method. An exception can be rethrown.

Is This Answer Correct ?    1 Yes 0 No

what is difference between throw and throws in exception?..

Answer / amol nakhwa

/*
Save this file as "TestCircle.java"
*/



class NegativeRadiusNotAllowedException extends Exception
{
public String getMessage()
{
return "Radius should be positive number only!";
}
}

class Circle
{
public void calculateArea(int rad) throws
NegativeRadiusNotAllowedException
{
if (rad < 0)
{
throw new NegativeRadiusNotAllowedException();
}
double ar = 3.1415*rad*rad;
System.out.println("Circle Radius = "+ rad + " and Area =
"+ar);
}
}



public class TestCircle
{
public static void main (String args[])
{
Circle c = new Circle();

try
{
//int no1 = Integer.parseInt(args[0]);
//int no2 = Integer.parseInt(args[1]);
c.calculateArea(9);
c.calculateArea(-9);
}
catch (NegativeRadiusNotAllowedException e)
{
System.out.println(e.getMessage());
}
catch (NumberFormatException e1)
{
System.out.println(e1.getMessage() +" is not a valid
integer");
}
catch (Exception e2)
{
System.out.println(e2.getMessage());
}
}
}

Is This Answer Correct ?    1 Yes 0 No

what is difference between throw and throws in exception?..

Answer / sathiya moorthy v

throw --> manually throw exception.
Ex: throw ThrowableInstance;
throws -->Any exception that is thrown out of a method must
be specified as such by a throws clause
Ex: <access specifier> <return type> <methodName> throws
Exception{
}

Is This Answer Correct ?    1 Yes 0 No

what is difference between throw and throws in exception?..

Answer / basha

throw & throws is a keyword in Exceptions.
throw is to throw the exception defined by User.
Ex:if user enter wrong pin number,it shows error
(Exception). This s the exception used to throw it.

And throws is that which will throw the error as the Cash
Dispenser not having the cash to dispense. This type of
error(exception) is defined by throws keyword.

Is This Answer Correct ?    1 Yes 0 No

Post New Answer

More Core Java Interview Questions

What is a null class?

0 Answers  


How many digits is int32?

0 Answers  


Why do we need singleton class?

0 Answers  


What is the original name of java?

0 Answers  


How do you write a conditional statement?

0 Answers  


11. static class A { 12. void process() throws Exception { throw new Exception(); } 13. } 14. static class B extends A { 15. void process() { System.out.println(”B”); } 16. } 17. public static void main(String[] args) { 18. new B().process(); 19. } What is the result? 1 B 2 The code runs with no output. 3 Compilation fails because of an error in line 12. 4 Compilation fails because of an error in line 15.

6 Answers  


What is the similarity between dynamic binding and linking?

0 Answers  


What is binary tree in java?

0 Answers  


What is sleep method?

0 Answers  


2) Suppose there are 5 directories having lot of files (say txt files) in each directory. 2 things :- 2.1) You want to search for filenames which have a particular pattern. 2.2) Out of these filtered files you want to search for a particular keyword or a search string. How can you achieve this?

0 Answers   RBS, TCS,


can you create interface instance ?

54 Answers   Fidelity, TCS,


How do you check if two strings are equal in java?

0 Answers  


Categories