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

Explain about features of local inner class?

850


Name the components that are termed to be Heavy-weight component but available in Light-weight components?

2224


Can we assign integer value to char in java?

724


Is 0 a real number?

798


Explain the difference between map and flatmap stream operation?

1047


What is the purpose of java?

779


How many JVMs can run on a single machine and what is the Just-In-Time(JIT) compiler?

826


Why we override equals() method?

796


How to make a class or a bean serializable?

751


What is final method in java?

765


What is a boolean field?

742


What is gui programming?

740


What does || mean in code?

808


What is java virtual machine and how it is considered in context of java’s platform independent feature?

869


How would you convert bytes to string?

774