how can u handle run time exception in java? explain with
brief explanation with examples?

Answer Posted / pavithra

public class ExceptionalClass {
public void method1() throws CheckedException {
// ... some code
throw new CheckedException( "something bad
happened" );
}
public void method2( String arg ) {
if( arg == null ) {
throw new NullPointerException( "arg passed to
method2 is null" );
}
}
public void method3() throws CheckedException {
method1();
}
}

Contrast method1() with method2(). When you
make a call to method2(), you don't have to do so within a
try/catch block. Since you do not have to catch the
exception, the exception is said to be unchecked; it is a
runtime exception. A method that throws a runtime exception
need not declare the exception in its signature.

Is This Answer Correct ?    9 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can main() method in java can return any data?

642


What are implicit objects in java?

549


Is age a discrete variable?

526


What is the set interface in java programming?

623


Is a copy constructor?

572






What must a class do to implement an interface in java programming?

533


Differentiate between static and non-static methods in java.

559


What is difference between float and double?

496


What is a boolean structure?

554


What's the purpose of static methods and static variables?

591


What is stack class in java?

538


Can one thread block the other thread?

601


What is abstract class? Explain

593


What are the main features of java?

526


Write a method that will remove given character from the string?

569