java exception handling

Errors and Exception Handling in Java

Current Status
Not Enrolled
Get Started

The exception handling in Java is a special form of Error handling. The following errors typically occur during programming:

Syntactic errors: These are already recognized and written by the compiler. The program cannot be compiled by the compiler until it has been corrected

Logical errors and bugs: are usually difficult to localize (e.g. + and – reversed). These errors can be caused by the systematic output of your own debug information or can be fixed with the help of a debugger.

Runtime error: Most of the time, the source of the error is located outside the program. User information or resource requirements (for example file accesses) are common causes of these types of errors. They must be intercepted or dealt with in the program.


Exceptions are used to spatially separate the occurrence and detection of a bug in the code either the code should not use complex error handling for a better overview to be interrupted or meaningful error handling is not possible at the point at which it occurred, which is why the error occurred is transferred to another program block or a calling method. Exceptions are implemented as normal classes in Java. There are already predefined classes for the most important exceptions. They are automatically integrated by the “java.lang” package and can be used without import instructions. The upper class of all exceptions is the Throwable class. The Throwable class provides important constructors and methods for Exception handling. Java distinguishes between two types of exceptions:

Checked Exceptions

These are usually exceptions that are checked at runtime. A program can recover from it. Software developers are expected to review these exceptions. This is often solved by a try-catch block and the throw statement. These are either predefined or self-defined exceptions. You can also create your own exception classes to represent problems that can occur within the classes you have written.

Unchecked Exceptions

On the other hand, there are unchecked exceptions. These are exceptions that are not checked at compile time and should therefore not occur. They occur anyway, but do not need to be treated. Instead of handling the exception at runtime, the programming problem should be resolved, otherwise the program crashes with an error message.

Exceptions in software development are used to ensure that certain situations are handled separately. Certain exceptions are thrown when a problem is detected and allow error handling anywhere in the code.