Contents of page >
- 1) What are checked exceptions in java
- 2) Advantage/Benefit of using checked/compiletime Exception in java >
- 3) Example of checked exceptions in java
- 4) Which classes are which checked exceptions in java?
1) What are checked exceptions in java
Checked exceptions are those which need to be taken care at compile time.
2) Advantage/Benefit of using checked/compiletime Exception in java >
We cannot proceed until we fix compilation issues which are most likely to happen in program, this helps us in avoiding runtime problems upto lot of extent in java.
3) Example of checked exceptions in java
Example - FileNotFoundException - Until we handle this exception, user will face compilation error, because at runtime there is huge probability of file missing in the directory.
Most common and frequently occurring checked (compile time) in java >
IOException in java
FileNotFoundException in java
EOFException occurs and how to avoid it in java
SQLException in java
What is java.lang.InterruptedException in java
when java.lang.ClassNotFoundException occurs in java
Solve InvalidClassException in java
4) Which classes are which checked exceptions in java?
The class Exception and all its subclasses that are not also subclasses of RuntimeException are checked exceptions.
Now, i’ll be explaining you how checked exception was propagated.
Let’s see step by step what happened in above program >
- JVM called main method
- step 1 - main called method1()
- step 2 - method1 called method2()
- step 3 - method2 called method3()
- step 4 - method3 propagated exception to method2() using throws keyword.[because, checked exceptions are not propagated automatically]
- step 5 - method2 propagated exception to method1() using throws keyword.[because, checked exceptions are not propagated automatically]
- step 6 - method2 propagated exception to main() using throws keyword.[because, checked exceptions are not propagated automatically]
- main() propagated exception to JVM using throws keyword.[because, checked exceptions are not propagated automatically]
/** Copyright (c), AnkitMittal JavaMadeSoEasy.com */
RELATED LINKS>
Labels:
Core Java