Java Exceptions Question Answers

Java Exceptions - Question & Answers for Beginners

 

 

 

Some useful bits on java Exception to revise your subject that you learned in the class lesson. If not yet, please click the above top right link to go to lesson.

 

What is Exception ?
Exception is nothing but a runtime error. Handling exception is called as Exception Handling.
 

How many types of errors in programming.
1.    Syntactical errors (Grammatical errors) occurs at compile time.
2.    Semantic errors  (Logical errors) occurs at runtime.
 

 

What is the mechanism for handling exceptions in Java?
--Exception handling in Java is achieved through try, catch, and finally blocks.
 

What is the parent class of Exception.
--Throwable
In java, All classes are by default extended by which class.

-- Object

How many types of keyword java uses to handle exceptions, What are they?

Java provided 5 keywords  to handle exceptions.
1.    try 
2.    catch 
3.    finally
4.    throw
5.    throws

Divide by zero throws which exception.

ArithmeticException
 

What is checked Exceptions
Checked Exceptions are known during the compilation process.
 

What are Unchecked Exceptions
Unchecked Exceptions or run-time exceptions occur during program execution.

Give two Unchecked Exceptions examples.

ArithmeticException, 
NullPointerException, 
ArrayIndexOutOfBoundsException etc.


What exception thrown if char entered, in place of int value.

NumberFormatException
 

What is ArrayIndexOutofBoundException
– If there are no sufficient elements in an array.
 

What is the use of finally?
--finally, block to clean-up resources.
 

Where finally block is written in handling exception.
-- Finally block written after the catch block.
 

What is null pointer exception.
NullPointerException – It occurs when trying to read value from null variable.
 

What is Nested catch.
One try..catch, inside another try...catch block.

What printStckTrace()  method will do in Java exceptions

This is method is declared in Throwable class. Traces the error where exactly it originated by displaying the line no.

How a custom or user-defined Exceptions are created?

By extending Exception class. In other words, exception can be constructed by creating a subclass of the ‘Exception’ class.

Built-In Exceptions
Provided by Java libraries are known as Built-in exceptions. All the checked and unchecked exceptions comes under this category.

User-defined Exceptions
In some  scenarios users needs an exception that is not covered by the built-in libraries, Java provides an option to create a custom exception.

 

 

 Java Tutorial Home

 

Comments

Popular posts from this blog

Using javascript pass form variables to iframe src

Creating a new PDF by Merging PDF documents using TCPDF

Import excel file into mysql in PHP