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
Is arraylist zero based?
Differentiate jar and war files?
What is the use of parseint in java?
What is unicode used for?
How do I print a “?
What is a jit compiler?
What if the main() method is declared as private? What happens when the static modifier is removed from the signature of the main() method?
Why do we create threads in java?
What are the Static and Dynamic Variables? Differentiate them.
What are the five major types of reference sources?
What is javac used for?
What will happen when using pass by reference in java?
What is the difference between yield() and sleep()?
List some important features of java 10 release?
What is difference between equals and hashcode method?