adspace


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

What is java string pool?

1083


Differentiate between static and non-static methods in java.

1128


Is minecraft 1.15 out?

1045


What is an object in java and how is it created?

1140


Realized?

2264


Explain public static void main(string args[]) in java.

1077


What is the difference between equals() and == in java?

1040


What are the differences between heap and stack memory in java?

1140


Write a program to find the whether a number is an Armstrong number or not?

1098


What is parsing in java?

1041


explain different ways of using thread? : Java thread

1082


Write a java program to find the route that connects between Red and Green Cells. General Rules for traversal 1. You can traverse from one cell to another vertically, horizontally or diagonally. 2. You cannot traverse through Black cells. 3. There should be only one Red and Green cell and at least one of each should be present. Otherwise the array is invalid. 4. You cannot revisit a cell that you have already traversed. 5. The maze need not be in the same as given in the above example

2665


Write a program to print count of empty strings in java 8?

1086


How to create a base64 decoder in java8?

1138


What is the difference between break and continue statements?

1127