How to handle checked exceptions in java?
we can use Throws to tell that we can't handle it and propagate it to parent functions.
we can use try-catch block to handle exceptions.
we can use either option 1 or option 2 to handle the exceptions.
If an checked exceptions happens, then it is mandatory for that function to handle it by try-catch block only.
There are two ways to handle a checked exception.
1. we can use "Throws" clause to tell that we can't handle that exception, and propagate that exception to parent functions.[or]
2. we can use try-catch block to handle that exception.
Note: If you don't do any of the above two options, then compiler will throw error if it is a checked exception.
Back To Top