posted 20 years ago
I have the following code which does not compile. Gives a compilation error: C:\JavaExamples\SL275Lab\mod01\examples\PassA.java:25: exception Level2Exception is never thrown in body of corresponding try statement
catch (Level2Exception e) {
^
1 error
When I interchange the catch statements, it compiles fine like below:
I fail to understand why in the first case was it complaining that Level2Exception is never thrown in the body of the corresponding try statement when I clearly have this in the try code:
Or is it throwing the compilation error because the exception heirarchy is violated since Level1Exception is caught before Level2Exception is caught? In that case, the error message should be different than what I get.
Any thoughts on this is appreciated. Thank you!