1

I am very new to this topic. Please bare with my silly doubts. I have the following code where I get a name from user and if its null sone exception is thrown. But here i m not getting any exception it i enter null. Please help me

import java.io.*;
class dbz
{
    public static void main(String args[])
    {
        String s=null;
        try
        {

           BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
           s=br.readLine();
        }
        catch(IOException e)
        {
           System.out.println(e.getMessage());
        }
        System.out.println(s);
    }
}
2
  • Could you clarify what is happening, and what you expect to happen? It's not entirely clear to me what the problem is. Commented Oct 27, 2010 at 7:48
  • please include some more information regarding expected vs. actual behavior. Commented Oct 27, 2010 at 13:27

2 Answers 2

2

You will never receive null as user input from the console, and it would not trigger a IOException regardless.

Sign up to request clarification or add additional context in comments.

Comments

0

modify your code as below then you'll see the problem for yourself

import java.io.*; 
class dbz 
{ 
  public static void main(String args[])  throws IOException
  { 
       BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); 
       System.out.println(br.readLine()); 
   } 
} 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.