public class Box { public void doIt() { throw new Throwable(); } }
The above code does not compile. However if Throwable is replaced by Error it compiles fine.
I find this strange because Error descends from Throwable. So I would have expected the code not to compile if Error replaced Throwable in the above code.
Does anybody have any explanation of this anomaly ?
We cannot throw Thowable . we can throw Error , Exception which are dereived from Throwable. For error , it is not neccessary that we have to catch that exception(catch block) (or throws ) . But for Exception (for Checked exceptions only) , you have to catch by means of catch block or throws clause.