If I try to use IOException without the fully qualified name and without importing, I get a compilation error. But it doesn't happen when I do the same with, say, RuntimeException or Exception. Why is that?
Thanks
A user should not attempt to handle this kind of an exception because it will only patch the problem and not completely fix it.
yes you can. You can throw anything that extends Throwable - check the javadocs.
Usually, a RuntimeException indicates a programming error (in which case you can't "handle" it, because if you knew to expect it you'd have avoided the error).
RuntimeException is the superclass of those exceptions that can be thrown during the normal operation of the Java Virtual Machine. RuntimeException and its subclasses are unchecked exceptions.
Classes from package java.lang.
need not be imported. It's not just RuntimeException, but also stuff like Object and String.
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