【问题标题】:Java exception handling (IOException)Java 异常处理 (IOException)
【发布时间】:2018-06-03 08:24:06
【问题描述】:

/* 在上面的例子中,当它会显示 Catch 的输出时,即 [Error May be Occured in Input]。请给我输入。 */

 import java.io.IOException; 
    public class ThrowsClause 
    { 
         static boolean guess() throws IOException //Throws Clause
         { 
             char ch='r'; 
             System.out.print("Guess any Character(a-z) : "); 
             char n=(char)System.in.read(); 
             return(ch==n); 
          } 
         public static void main(String[] args) 
         { 
              boolean result; 
              try 
             { 
                  result=guess(); //Back to method
                  if(result==true) 
                     System.out.println("Your Guess is Perfect"); 
                  else 
                     System.out.println("Your Guess is Incorrect"); 
              } 
                  catch(IOException e) 
              { 
                     System.out.println("Error May be Occured in Input"); //I want input to display this statement as a output`
               } 
          } 
    } 

/* In this above example when it will display output of Catch i.e. [Error May be Occured in Input]. Please give me the input. */

【问题讨论】:

  • 你的问题是什么?
  • 如果你想以编程方式抛出任何异常。你可以 throw new IOException();随时随地!

标签: java


【解决方案1】:

如果出现IOException,您的程序只会打印Error May be Occured in Input 消息。 The Javadocs state that this will only happen if an input/output error occurs 在获取用户输入时。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-11-01
  • 2023-03-12
  • 2013-09-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多