Co-Authored By:
Exceptions are events that occur duringtheexecution of programs that disrupt the normal flow ofinstructions(e.g. divide by zero, array access out of bound, etc.).InJava, an exception is an object that wraps anerrorevent that occurred within a method and contains: Informationaboutthe error including its type.
Moreover, what is E in catch block?
Try defines a block of statements thatmaythrow an exception. When a specific type of exception occurs,acatch block catches the exception.
Regarding this, what are the different types of exception in Java?
Below is the list of important built-in exceptionsinJava.
- ArithmeticException. It is thrown when an exceptionalconditionhas occurred in an arithmetic operation.
- ArrayIndexOutOfBoundsException.
- ClassNotFoundException.
- FileNotFoundException.
- IOException.
- InterruptedException.
- NoSuchFieldException.
- NoSuchMethodException.
Java try and catch The try statement allows you to defineablock of code to be tested for errors while itisbeing executed. The catch statement allows youtodefine a block of code to be executed, if an error occursinthe try block.