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...


How can we handle runtime exceptions? write one sample
program? Can we write runtime exceptions beside the throws
key word? if yes write sample program?



How can we handle runtime exceptions? write one sample program? Can we write runtime exceptions be..

Answer / amit2009mca

there is no need to handle a runtime exception,
but acording to question
there are two types through which we could handle the
exception one is decalre the exception and other try catch
block.
so for this i'll show you the customize way for this.

class AmitSingh extends RuntimeException
{
}

class Amit
{
int number;
Amit(int number)
{
this.number = number;
}

public void method1()
{
try
{
if(number>5)
throw new AmitSingh();
}
catch(AmitSingh e)
{
System.out.println(e.printStackTrace());
}
public static void main(String []args)
{
Amit a = new Amit(20);
a.method1();
}
}

but i don't think there is need to this because jvm is
responsible for all that thanks AMIT SINGH09

Is This Answer Correct ?    2 Yes 1 No

Post New Answer

More Core Java Interview Questions

Is set thread safe java?

0 Answers  


How to make a class or a bean serializable?

0 Answers  


What is multiple inheritance & can we implement it in java?

6 Answers   Satyam,


What is the purpose of assert keyword used in jdk1.4.x?

0 Answers  


why string constant pool in java

2 Answers   TCS,


explain how many oops concepts available in java with realtime scenarios?

1 Answers   TCS,


Is void a data type?

0 Answers  


What is the difference between the boolean & operator and the && operator in java programming?

0 Answers  


How do you replace all in word?

0 Answers  


Why are the destructors for base class and derived class called in reverse order when the program exits

0 Answers   HCL,


What are filterstreams?

0 Answers  


Does .length start 0 java?

0 Answers  


Categories