When we have a custom Exception, say SkillRequiredException
, we check for some condition like checking the skill of the employee and if the condition fails we will throw SkillRequiredException
.
Till this I am fine and clear.
But lets take FileInputStream
class. It throws FileNotFound
checked exception. When I see FileInputStream
source code, I could not see anywhere - checking for some condition (and) throw FileNotFoundException
.
My question is, how JVM knows that file is not present and how the Exceptional Object created by JVM is identified as FileNotFoundException
with out using throw FileNotFoundException
in FileInputStream
class?
Well, if you check which methods are called by the constructor of FileInputStream
, you'll see that it eventually calls :
private native void open(String name) throws FileNotFoundException;
This is a native method, which means it's not written in Java and you can't see its code, but it can still throw a FileNotFoundException
exception.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With