【发布时间】: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