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 is an example of character?
What is the arraylist in java?
Is string is a class in java?
Define how does a try statement determine which catch clause should be used to handle an exception?
What are voids?
Why are generics used?
Can we have try without catch block?
What is udp in java?
How do you use compareto method?
Differentiate between array list and vector in java.
What is the difference between an object-oriented programming language and object-based programming language?
How can we make a class virtual?
What are the differences between throw and throws?
What checkbox method allows you to tell if a checkbox is checked?
What does indexof mean?