I am getting an error Error:(25, 13) java: unreported exception ExceptionA; must be caught or declared to be thrown
when trying to rethrow the exception.
I am still new to Java and my book uses the below to "rethrow," but I get an error at throw exception;
when attempting to rethrow even though this is based directly off of the book.
import java.io.IOException;
public class catchingExceptions {
public static void main(String args[]) {
throwExceptionA();
throwExceptionB();
throwNullPointer();
throwIOException();
}
public static void throwExceptionA() {
try {
throw new ExceptionA();
} catch (ExceptionA exception) {
System.err.printf("Exception: %s \n", exception);
System.err.println("ExceptionA handled in method throwExceptionA \n");
throw exception;
}
}
public static void throwExceptionB() {
try {
throw new ExceptionB();
} catch (ExceptionB exception) {
System.err.printf("Exception: %s \n", exception);
System.err.println("ExceptionB handled in method throwExceptionB \n");
}
}
public static void throwNullPointer() {
try {
throw new NullPointerException();
} catch (NullPointerException exception) {
System.err.printf("Exception: %s \n", exception);
System.err.println("NullPointerException handled in method throwNullPointerException \n");
}
}
public static void throwIOException() {
try {
throw new IOException();
} catch (IOException exception) {
System.err.printf("Exception: %s \n", exception);
System.err.println("IOException handled in method throwIOException \n");
}
}
}