当前位置: 技术问答>java相关
各位大虾!求救!!有一个关于调用输入类的程序,有一个错误,请指教!!
来源: 互联网 发布时间:2015-05-13
本文导语: import java.io.*; class read1{ void readline() throws Exception{ BufferedReader br=new BufferedReader( new InputStreamReader(System.in)); Stri...
import java.io.*;
class read1{
void readline() throws Exception{
BufferedReader br=new BufferedReader(
new InputStreamReader(System.in));
String m;
System.out.println("input a number");
m=br.readLine();
System.out.println("the string is "+m);
}
}
public class read{
public static void main(String args[]){
read1 a=new read1();
try{
a.readline();}// D:javacread.java:17: 未报告的异常 java.lang.Exception ;必须被捕获或被声明抛出
catch (IOException e){
System.out.print(e);
}
}
}
class read1{
void readline() throws Exception{
BufferedReader br=new BufferedReader(
new InputStreamReader(System.in));
String m;
System.out.println("input a number");
m=br.readLine();
System.out.println("the string is "+m);
}
}
public class read{
public static void main(String args[]){
read1 a=new read1();
try{
a.readline();}// D:javacread.java:17: 未报告的异常 java.lang.Exception ;必须被捕获或被声明抛出
catch (IOException e){
System.out.print(e);
}
}
}
|
把 IOException 改成 Exception