Hi, if try to catch something that cannot be thrown from anywhere, I'll have an unreachable code and an compile error. For instance, this code gives me a compile error.
I understand this fine. But when you don't use Exception subclasses, the following code compiles fine. In other words, if you try to catch Exception base class, it's fine, it doesn't generate compile errors.
Originally posted by Leandro Melo: In other words, if you try to catch Exception base class, it's fine, it doesn't generate compile errors.
Can anyone clarify this behaviour for me?[/QB]
Sure ;-) You can catch any unchecked exceptions at any time. RuntimeException and it's subclasses are instanceof Exception, therefore you can catch it. The same applies to Error and its subclasses. And, obiously, you could also try to catch Throwable.