Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java异常处理(IOException)_Java - Fatal编程技术网

Java异常处理(IOException)

Java异常处理(IOException),java,Java,/*在上面的示例中,它将显示Catch的输出,即[输入中可能出现错误]。请给我输入*/ import java.io.IOException; public class ThrowsClause { static boolean guess() throws IOException //Throws Clause { char ch='r'; System.out.print("G

/*在上面的示例中,它将显示Catch的输出,即[输入中可能出现错误]。请给我输入*/

 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. */

如果出现
IOException
异常,您的程序将只打印输入消息中可能出现的
错误。获取用户输入时。

您的问题是什么?如果您想以编程方式抛出任何异常。您可以抛出新IOException();在任何你想要的地方!您将提供什么输入。因为我尝试了多输入组合。有关
IOException
的更多信息,请参阅此问题: