"error: unreported exception EmptyFileException; must be caught or declared to be thrown" in java when compiling my driver
<p>First time posting here, if the format is awry I'll try to fix it. Anyway so I keep getting this error in java when trying to run my driver. The goal of the program is to write and then read from a file, I wrote to the file just fine and now I'm trying to read from it and here is the error:</p>

<p>unreported exception EmptyFileException; must be caught or declared to be thrown</p>

<p>University ufl = University.readFromFile("university.txt");</p>

<pre><code>//read from file
public static University readFromFile(String filename) throws EmptyFileException {
    File file = new File(filename);
    University university = null;
    Scanner in = null;
    try {
        in = new Scanner(file);
        String str = in.nextLine();
        Scanner in2 = new Scanner(str).useDelimiter(":");
        in2.next(); 
        String uName = in2.next();

        //Read University info
        str = in.nextLine();
        in2 = new Scanner(str).useDelimiter(":");
        in2.next(); 
        String uTerm = in2.next();
        str = in.nextLine();
        in2 = new Scanner(str).useDelimiter(":");
        in2.next(); 
        int uYear = in2.nextInt();
        str = in.nextLine();
        in2 = new Scanner(str).useDelimiter(":");
        in2.next(); 
        int uNumStudents = in2.nextInt();
        str = in.nextLine();
        in2 = new Scanner(str).useDelimiter(":");
        in2.next(); 
        int uNumInstructors = in2.nextInt();
        str = in.nextLine();
        in2 = new Scanner(str).useDelimiter(":");
        in2.next(); 
        int uNumCourses = in2.nextInt();

        //Create and read arrays of objects
        Student[] uStudents = new Student[uNumStudents];
        for(int i = 0; i &lt; uNumStudents; i++)
                        uStudents[i] = readStudent(in);

        Instructor[] uInstructors = new Instructor[uNumInstructors];
        for(int i = 0; i &lt; uNumInstructors; i++)
                        uInstructors[i] = readInstructor(in);

                    //Create array of possible TAs to pass into readCourse method
                    GradStudent[] gStudents = new GradStudent[uNumStudents];
                    for(int j=0; j&lt;uStudents.length; j++) {
                        for(int i=0; i&lt;uStudents.length; i++) {
                            if(uStudents[i] instanceof GradStudent)
                                gStudents[j] = (GradStudent) uStudents[i];
                        }
                    } 

        Course[] uCourses = new Course[uNumCourses];
        for(int i = 0; i &lt; uNumCourses; i++)
                        uCourses[i] = readCourse(in, uInstructors, gStudents, uStudents);

        //Create University object
        university = new University(uName, uTerm, uYear, uStudents, uInstructors, uCourses);
        return university;

    } catch (FileNotFoundException fe) {
    fe.printStackTrace();
    return null;
}
}
</code></pre>

<p>And the code for my EmptyFileException is </p>

<pre><code>public class EmptyFileException extends Exception {
String filename;

EmptyFileException() {
}

EmptyFileException(String filename) {
    this.filename = filename;
}

public String toString() {
    return "The file " + filename + " is empty.";


}
</code></pre>

<p>}</p>

<p>And the driver is</p>

<pre><code>public class TestDriver2 {

public static void main(String[] args) {

    University ufl = University.readFromFile("university.txt");

            if (ufl != null) {
                System.out.println("\n--Printing out University info--");
                System.out.println(ufl);

                System.out.println("\n--Printing out Students info--");
                Student[] students = ufl.getStudents();
                for (Student s : students)
                        System.out.println("\n" + s);
            }
}
</code></pre>

<p>}</p>

<p>Any help would be appreciated. And in case it wasn't clear, the first 2 files compile just fine, only the driver won't compile (which was given to me by my teacher).</p>

<p><strong>Update</strong></p>

<p>Added the <code>throws</code> clause and it compiled, didn't figure to change the code my teacher gave me. </p>

<p>However now I keep getting this error:</p>

<pre><code>Exception in thread "main" java.util.InputMismatchException
 at java.util.Scanner.throwFor(Scanner.java:909)
 at java.util.Scanner.next(Scanner.java:1530)
 at java.util.Scanner.nextInt(Scanner.java:2160)
 at java.util.Scanner.nextInt(Scanner.java:2119)
 at University.readFromFile(University.java:174)
 at TestDriver2.main(TestDriver2.java:8) 
</code></pre>
