java exceptions tutorial

java exceptions tutorial is one of the most important topics in Java. Bodhak tutor explained very well and in detailed covering all the important topics related to exceptions.

The detailed explanation provided with syntax and where ever needed they have explained with the programs. The Programs execution and implementation are given in detailed. one of the most important topics in point of interviews.


java exceptions tutorial

Exceptions :

Types of errors:

Compile time errors

Runtime errors


Compile time error:  the error which occurs during the compile of the program is called compile time error. All syntax error is called compile time errors.

If there is an error during compile time, the Java compiler does not generate bytecode.

Runtime errors: The errors which occur during execution of the program are called runtime errors  All run-time errors are coded exceptions.

When an exception occurs within program execution is terminated. In order to avoid abnormal termination of the program, we required exception handlers.

what is an exception:

the exceptional event typically an error that occurs during runtime.

Cause normal program flow to be disrupted



Divide by zero errors

Accessing the elements of an array beyond its range

Invalid Input

Hard disk crash

Opening a nonexistent file

Heap memory exhausted

what happens when an exception occurred?

When an exception occurs within a method, the method typically creates an exception object and hands it off to the runtime system.

Creating an exception object  handing it to the runtime system is called “ throwing an exception”

Exception object contains information about the error, including its type and the state of the program when the error occurred

The runtime searches the call stack for a method that contains an exception handler When appropriate handler is found, the runtime system passes the exception to handle

An exception handler is considered appropriate if the type of exception object thrown matches the type that can be handled by handler

The exception handler chosen is said to catch the exception

If the runtime system exhaustively searches all the methods on the call stack without finding an appropriate exception handler, the runtime system ( and consequently, the program) terminates and uses the default exception handler