Search code examples
javaexceptioncompilationinputmismatchexception

I want to catch InputMismatchException but it shows compile time error


I get the following error while compiling:

filimon.java:12: error: cannot find symbol
                }catch(InputMismatchException ime){
                       ^
  symbol:   class InputMismatchException
  location: class filimon
1 error

My source code is:

class filimon{
    public static void main(String[] args) {
        Scanner s=new Scanner(System.in);
        try{
            System.out.println("enter 2 integer values");
            int a=s.nextInt();
            int b=s.nextInt();
            System.out.println("value of a: "+a);
            System.out.println("value of b: "+b);
        }catch(InputMismatchException ime){
            System.err.println("please enter only number value");
        }
        catch(Exception e){
            System.err.println(e);
        }
    }//main
}//filimon

What is the problem? Please help me.


Solution

  • Add import java.util.InputMismatchException;