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 / 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 |
What is the difference in between cpp and java? Can u explain in detail?
Which browsers work with java?
What will happen when using pass by reference in java?
When does the compiler supply a default constructor for a class?
Explain listiterator and methods in listiterator?
What is starvation?
What are the differences between include directive and include action?
What advantage does an entity bean have over a sessin bean?
What is the difference between checked exception and unchecked exception?
1) Find the Merge point of two linked lists. 2) Swap two bits of integer. 3) Reverse individual words of the sentence. 4) Reverse string without using temp string.
What are the different data types in java?
What does localhost mean?