I have two exception classes that contain the same variable name (but in reality differ in other respects).
class FooException extends Exception
{
public String member;
}
and
class BarException extends Exception
{
public String member;
}
At a catch site, I want to use a multicatch
catch (FooException | BarException e) {
System.out.println(e.member);
}
However this issues the compile error
System.out.println(e.member); symbol: variable member location: variable e of type Exception
The solution is obviously to break up the multicatch and duplicate the function body. But why doesn't the language "know" that member is available for all the exceptions in the multicatch? To me it seems to search for a common base class, and sets the type of e to that. Is that the correct way to look at this?