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

what do you mean by stream pipelining in java 8? Explain

0 Answers  


How can an exception be thrown manually by a programmer?

0 Answers  


Explain differences between checked and unchecked exceptions in java?

0 Answers  


What is an escape character in java?

0 Answers  


Nullpointer exception is a very common exception. Why is it not made as a checked exception?

2 Answers   Ness Technologies,






What is empty string literal in java?

0 Answers  


Why we cannot override static method?

0 Answers  


What are peerless components in java programming?

0 Answers  


What is difference between throw and throws ?

0 Answers   Cyient,


abstract class A{ int list []=new int [100]; A(int x,int y){ rondom n=new rondom(); for (int i==;i<100;i++); list [i]=x+r.next int(y-x+1); abstract sort (); abstract binary sarch(int temp); class B extends A{

3 Answers  


Do I need java on my pc?

0 Answers  


What means public static?

0 Answers  


Categories