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?

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

What is user defined exception in Java?

615


What is the difference between normal report & matrix report?

575


How do you get length in java?

566


Realized?

1666


What is object class in java?

507






What is the use of using enum to declare a constant?

562


what is mutual exclusion? How can you take care of mutual exclusion using java threads? : Java thread

690


Is null a string in java?

558


What does  mean in regex?

575


What is final keyword in java? Give an example.

580


What is a string what operation can be performed out with the help of a string?

516


What is the differences between c++ and java? Explain

589


How to create an interface?

629


What is the difference between a local variable and an instance variable?

554


Is it possible to define a method in java class but provide it’s implementation in the code of another language like c?

588