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
Why we cannot override static method?
How does java enable high performance?
What is connection class in java?
How to convert string to char and vice versa?
Explain java code for recursive solution's base case?
Is hashmap thread safe?
What will be the initial value of an object reference which is defined as an instance variable?
What is the difference between public, private, protected, and friend access?
when a request is generated from apache tomcat 5.5 and goes to oracle 10g or mysql,,, how the oracle or mysql reads the request as apache is a web server and oracle 10g is application server? when the oracle 10g provides response, how the apche tomcat reads it???
Does list allow duplicates in java?
How can we find the actual size of an object on the heap?
Can we define package statement after import statement in java?
What is the size of boolean variable?
How do you sort in ascending order in java?
What are the escape sequences in java?