5. Exceptions
Activity 1: Designing an Exception Class Logging Data
Solution
- Import the relevant classes needed for this program to work:
NoSuchFileExceptionandlogging.import java.nio.file.NoSuchFileException; import java.util.logging.*;
- Make your own methods for issuing exceptions, start by creating one for the
NullPointerExceptioncase.public static void issuePointerException() throws NullPointerException { Â Â Â Â throw new NullPointerException("Exception: null pointer"); } - You will also need a method for the case the file is not found:
NoSuchFileException.public static void issueFileException() throws NoSuchFileException { Â Â Â Â throw new NoSuchFileException("Exception: file not found"); } - Back to the
Mainmethod, create theloggerobject that will be reporting the exceptions and their severity level.Logger logger = Logger.getAnonymousLogger();
- Capture the argument passed to the script via the CLI...