I made my own excpetions and I have to print the error message from the exception with a method that uses getMessage(). e.getMessage() is highlighted and it says result of Throwable.getMessage is ignored. For example if I input a number below 5 it prints SmallException caught but doesn't print Number was below 5.
try {
testValue(testNum);
System.out.println("Number was between 5-10.");
} catch(SmallException e) {
System.out.println("SmallException caught!");
printErrorMessage(e);
} catch(BigException e) {
System.out.println("BigException caught!");
printErrorMessage(e);
}
}
public static void printErrorMessage(Exception e) {
e.getMessage();
}
public static void testValue(int num) throws SmallException, BigException {
if(num < 5) {
throw new SmallException("Number was below 5.");
} else if(num > 10) {
throw new BigException("Number was over 10.");
}
}
}
class SmallException extends Exception {
SmallException() {
super();
}
SmallException(String message) {
super(message);
}
}
class BigException extends Exception {
BigException() {
super();
}
BigException(String message) {
super(message);
}
}
I can't think of anything to try :(