Program not throwing exception
I have written the below Fibonacci series program that accepts an integer to display that many numbers in the series. Works fine, but when you enter a negative number, it is supposed to throw the exception and instead it prints out the first number. It does throw an exception if I enter a character. Can you please help? Also, can you suggest if I am writing the program in an efficient way?
import java.util.Scanner;
public class Fibonacci {
public static void main(String[] args) {
int n, a, b, c, i;
try{
System.out.println("Please enter the number of fibonacci series you would like to print");
Scanner input = new Scanner(System.in);
n = input.nextInt();
while (n == 0) {
System.out.println("please enter a number greater than zero");
n = input.nextInt();
}
a = 1;
b = 1;
System.out.println(a);
for(i = 2; i<=n; i++){
System.out.println(b);
c = a + b;
a = b;
b = c;
}
} catch(Exception E){
System.err.println("You did not enter a valid integer number");
}
}
}