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
Can main() method in java can return any data?
What are implicit objects in java?
Is age a discrete variable?
What is the set interface in java programming?
Is a copy constructor?
What must a class do to implement an interface in java programming?
Differentiate between static and non-static methods in java.
What is difference between float and double?
What is a boolean structure?
What's the purpose of static methods and static variables?
What is stack class in java?
Can one thread block the other thread?
What is abstract class? Explain
What are the main features of java?
Write a method that will remove given character from the string?