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


Please Help Members By Posting Answers For Below Questions

Why we cannot override static method?

767


How does java enable high performance?

929


What is connection class in java?

732


How to convert string to char and vice versa?

739


Explain java code for recursive solution's base case?

784


Is hashmap thread safe?

770


What will be the initial value of an object reference which is defined as an instance variable?

906


What is the difference between public, private, protected, and friend access?

788


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???

1910


Does list allow duplicates in java?

702


How can we find the actual size of an object on the heap?

1072


Can we define package statement after import statement in java?

779


What is the size of boolean variable?

829


How do you sort in ascending order in java?

681


What are the escape sequences in java?

758