Question : What is Exceptions in Java
Program?
Ans-- An exception is an
abnormal condition that arises in a code sequence at run time. In other words,
an exception is a run-time error must be checked and handled manually.
Exceptions can be generated by the
Java run-time system (or java virtual machine, JVM ), or they can be manually
generated by your code.
Exception
is of two type-
1. Check Exception or Compiletime
Exception. An exception which generate by
programming error like user written program or code and must be
handle at time of compilation of program.
2.
Uncheck Exception or Runtime Exception. An
exception which can generate at the runtime of program,
the compiler doesn’t force the programmers to catch the exception.
Question: Introduction of Exception Handling
in Java.
Ans-- When an exceptional condition arises, an object representing that
exception is created and thrown in the method that caused the error. That method
may choose to handle the exception itself, or pass it on. Java exception
handling is managed via five keywords: try, catch, throw, throws, and finally.
Try block is used to monitor for exceptions, Catch
block is
used to catch this exception and handle it in some rational manner. To manually
throw an exception, use the keyword throw. Any code that must be executed
before a
method returns is put in a finally block.
The following
syntax represent exception handling
try
{
// block of code to monitor for errors
}
catch (Exception exObject) {
// exception handler for ExceptionType1
}
finally
{
// block of code to be executed before try block ends
}
Question: Explain the Throwable Class in Java
Program.
Ans-- All the types of exception are built-in subclasses of the class Throwable. Thus, Throwable is at the top of the exception class hierarchy.
Throwable are two subclasses that partition
exceptions into two different manner -
1.
Exception-This class is used for exceptional conditions that user
should catch through declare it in a throws clause.
2. Error-which defines
exceptions that are not expected to be caught under normal circumstances by
program or code.