【发布时间】:2014-10-24 00:05:38
【问题描述】:
由于某种原因,我收到“必须捕获或声明抛出未报告的异常 java.io.ioexception”。我在这个方法中抛出了一个 I/O 异常:
private void setChar() throws IOException
{
try
{
int data = in.read();
if(data==-1)
{
eof = true;
}
else
{
currentChar = (char) data;
}
}
catch (IOException e)
{
System.exit(0);
}
}
我在这里调用方法(在构造函数中):
private BufferedReader in;
private char currentChar;
private boolean done;
public Scanner(InputStream inStream)
{
in = new BufferedReader(new InputStreamReader(inStream));
done = false;
getNextChar();
}
public Scanner(String inString)
{
in = new BufferedReader(new StringReader(inString));
done = false;
setChar();
}
我是否调用/抛出了错误的异常?
【问题讨论】:
-
将头稍微向右转,然后阅读相关部分。
标签: java exception exception-handling io ioexception