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
What does indexof return in java?
What is return keyword in java?
What is the use of pattern in java?
Is java jre still free?
What are the two types of java?
What is printwriter in java?
Do I need to import java.lang package any time? Why?
Define packages in java?
How do you write a conditional statement?
What is a conditional statement explain with example?
What is lastindexof in java?
What is a default constructor and also define copy contrucyor?
Can we use catch statement for checked exceptions when there is no chance of raising exception in our code?
What does the exclamation mark mean in java?
enlist some features of jdk.