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
how to open and edit XML file in Weblogic???
Difference between operator overloading and function overloading
How do you write a conditional statement?
Explain try and catch keywords in java?
Difference between character constant and string constant in java ?
What is the use of toarray () in java?
How do you use wildcards?
how to split string in java?
Explain differences between checked and unchecked exceptions in java?
Difference between serialization and deserialization in java?
What is variable and constant explain with example?
What does sprintf return?
What is final variable?
How to invoke external process in java.
What is the full name of java?