I did notice a weird behaviour about the static and non-static inner exception classes.
For example the below code will not compile:
public class MyClass<T> {
private class MyInnerException extends Exception { // won't compile
..
}
}
But the below code will compile:
public class MyClass<T> {
private static class MyInnerException extends Exception { // will compile
..
}
}
Why is this behaving this way?
One thing is for sure that we cannot have Generic exceptions due to type erasure but then the above is not a Generic exception class but it is inside the Generic class. But if it is static it is allowed but if it is non-static it is not allowed?
Follow up question, is generic exception not allowed just because of the type erasure feature of Generic like it mentioned here: https://www.mscharhag.com/java/java-exceptions-and-generic-types Or there is some other reason to it?