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
Does java trim remove newline?
Does every java program need a main?
What are the advantages of packages in java?
Why java is secure? Explain.
Explain serialization and deserialization in java?
Distinguish between a predicate and a function?
What is the difference between stored procedure & function?
Which is a valid identifier?
Why collection is called framework in java?
What restrictions are placed on method overriding?
List out five keywords related to exception handling ?
What is the difference between Array and Hash Table?
What is singleton class in ruby?
Can we override private methods?
What is square root in java?