Different types of Errors in Java.
Before studying exception we must first know different types of errors:
- Syntax error or compile time error.
- Logical error.
- Runtime error.
Explanation
Syntax error:The error which occurs at compile time when there is mistake in the syntax of code.
Logical error: The error which the program compiles but the answer is not correct. This is due to some logical mistakes in the program.
Runtime error: The error which occurs at runtime. The runtime error is known as exception.
What is Exception in Java?
The runtime error is known as Exception.Example: If you divide a number by zero the execution of the program stops working, at that moment we can say that an exception has occured.
Types of Exceptions:
Checked Exception
Checked Exception which is also called compile-time exceptions occurs at the compile time. If the method contains the code that throws an exception, the programmer must provide a mechanism to catch it in the same method. Examples of Checked Exceptions are: IOException, SQLException, etc.
Unchecked Exception
Java Unchecked Exception which is also called Runtime Exceptions occurs at runtime. This occurs during the execution of the program. Examples of Unchecked Exceptions are: ArithmeticException, ArrayIndexOutOfBoundsException, etc.
Some common examples of Exception are:
- Divide by zero errors
- Accessing the array elements beyond the range.
- Invalid input
- Hard disk crash
- Opening a non-existent file
- Heap memory exhausted