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?

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Differentiate between overriding and overloading cases?

1105


What is file in java?

1029


What is protected in java?

993


What is callablestatement? How you can call stored procedure to pass in parameter?

1023


Explain jdk, jre and jvm?

968


How many bits is a 64 bit byte?

1078


Define how objects are stored in java?

1057


What is hash table in java?

1011


What is method in research paper?

1132


Explain exception chaining in java?

1167


What happens when you invoke a thread’s interrupt method while it is sleeping or waiting?

976


What is bom encoding?

995


Write a program to show whether a graph is a tree or not using adjacency matrix.

1096


What is module in oop?

1010


What does singleton class mean?

971