how can u handle run time exception in java? explain with
brief explanation with examples?
Answers were Sorted based on User's Feedback
Answer / 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 |
Answer / pavithra
Runtime exceptions represent problems that are detected by
the runtime system. This includes arithmetic exceptions
(such as when dividing by zero), pointer exceptions (such
as trying to access an object through a null reference),
and indexing exceptions (such as attempting to access an
array element through an index that is too large or too
small).
Runtime exceptions can occur anywhere in a program and in a
typical program can be very numerous. Typically, the cost
of checking for runtime exceptions exceeds the benefit of
catching or specifying them. Thus the compiler does not
require that you catch or specify runtime exceptions,
although you can.
| Is This Answer Correct ? | 5 Yes | 8 No |
What is a method header?
Can we have more than one package statement in source file ?
What is scope & storage allocation of static, local and register variables? Explain with an example.
I have a sorting issue with a Hashmap. My constraint is that I MUST use the Hashmap and work with existing code. I do a database query and place the results in a Hashmap. When I iterate thru the Hashmap, it loses the original alphabetical sorting done by the database. So, my problem is that I must sort the results coming out of the Hashmap which is then placed into another class.
What is the purpose of skeleton and stub?
Difference difference paint() and paintcomponent()?
Can a static class have a constructor java?
What is constructor and virtual function? Can we call a virtual function in a constructor?
Explain about features of local inner class?
Which container method is used to cause a container to be laid out and redisplayed in java programming?
What is meant by anonymous class?
What is an interface in java? Explain