Java异常处理(IOException)
/*在上面的示例中,它将显示Catch的输出,即[输入中可能出现错误]。请给我输入*/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
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
的更多信息,请参阅此问题: