Learnitweb

What is an exception?

An exception is an event, which occurs during the execution of a program, that disrupts the normal flow of the program’s instructions. When an exception occurs within a method, the method creates an exception object and passes this to runtime system. This exception object contains information about the exception, like its type. Creating an exception object and handing it to the runtime system is called throwing an exception.

In Java, exception is represented as a class Exception of package java.lang.

public class Exception extends Throwable

Here Throwable class is the superclass of all errors and exceptions in the Java language. Only objects that are instances of this class (or one of its subclasses) are thrown by the Java Virtual Machine or can be thrown by the Java throw statement.