I'm currently working on some exception handling and have run into an issue when using a driver class. The driver errors: "Unreported exception java.io.FileNotFoundException; must be caught or declared to be thrown." I'm unable to edit the driver to add "throws FileNotFoundException" to main.
Here is a code snippet from the main program. I know I need to catch the exception with a try/catch but I can't figure out how to initialize the Scanner prior to the try block.
public program(String file1, String file2) throws FileNotFoundException
{
File f1 = new File(file1);
File f2 = new File(file2);
try(Scanner scan = new Scanner(f1); Scanner scan2 = new Scanner(f2);)
{
}
catch(FileNotFoundException e){}
int a = scan.nextInt(); //THIS IS WHERE I RUN INTO PROBLEMS (scan not found)
scan.nextLine();
int b = scan.nextInt();
}