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
Can we convert stringbuffer to string?
What is fail first in java?
Give the hierarchy of inputstream and outputstream classes.
what happens when a thread cannot acquire a lock on an object? : Java thread
How do I type unicode?
What is the difference between throw and throws keywords?
What are disadvantages of java?
When will we use them?
How do you define a parameter?
hi am an engineering student and my next plan is for ms in either in us or australia i got my passport but i dont know anything bout visa can u give brief idea 1)How to get prepared for visa and 2)How to apply for top universities and 3)How to pay the fee and so on These all are basic questions plz give me a clear idea
Write a program to reverse a number in java?
How many bits is a double?
What is data member in java?
For class CFoo { }; what default methods will the compiler generate for you>?
What is lazy initialization in java?