Sie sind auf Seite 1von 5

Exceptions

ETL LABS PVT LTD – JAVA PROGRAMMING 154


What is Exception Handling?
The Exception Handling in Java is one of the
powerful mechanism to handle the runtime
errors so that normal flow of the application
3
can be maintained.
Dictionary Meaning: Exception is an
abnormal condition.

ETL LABS PVT LTD – JAVA PROGRAMMING 155


try and catch
The try statement allows you to define
a block of code to be tested for errors
while it is being executed.

4 The catch statement allows you to


define a block of code to be executed, if
an error occurs in the try block.

The try and catch keywords come in


pairs:

ETL LABS PVT LTD – JAVA PROGRAMMING 156


Finally
The finally statement lets you execute code, 3
after try...catch, regardless of the result:

ETL LABS PVT LTD – JAVA PROGRAMMING 157


throw keyword

The throw statement allows you


Method Description to create a custom error.
reads the next byte of data from the
public abstract int
read()throws IOException
input stream. It returns -1 at the end of The throw statement is used
the file. together with an exception type.
There are many exception types
public int available()throws
returns an estimate of the number of available in Java:
bytes that can be read from the current ArithmeticException,
IOException
input stream. ClassNotFoundException,
ArrayIndexOutOfBoundsExcep
public void close()throws tion, SecurityException,
is used to close the current input stream.
IOException etc.

ETL LABS PVT LTD – JAVA PROGRAMMING 158

Das könnte Ihnen auch gefallen