public class C { public C() { } ....... ...... public String A(String B) throws IllegalArgumentException { if(B.indexOf('|')==-1) throw new IllegalArgumentException("");
} public static void main(String []args) { C c1=new C(); String str1="1,2,3"; String str2; try{ str2=c1.A(str1); //这里就提示错误 }catch(IllegalArgumentException e){
//处理错误 } } }
H:\javafile\20050419\Test.java:11: illegal start of expression throws new IllegalArgumentException("Wrong"); ^ H:\javafile\20050419\Test.java:31: 'void' type not allowed here System.out.println(e.printStackTrace()); ^ 2 errors
class Test { private int year; private int month; private int day;
{
public C()
{
} .......
...... public String A(String B) throws IllegalArgumentException
{
if(B.indexOf('|')==-1) throw new IllegalArgumentException("");
} public static void main(String []args)
{
C c1=new C();
String str1="1,2,3";
String str2;
try{
str2=c1.A(str1); //这里就提示错误
}catch(IllegalArgumentException e){
//处理错误
}
}
}
throws new IllegalArgumentException("Wrong");
^
H:\javafile\20050419\Test.java:31: 'void' type not allowed here
System.out.println(e.printStackTrace());
^
2 errors
{
private int year;
private int month;
private int day;
public String setDay(int y,int m,int d) throws IllegalArgumentException
{
if(d>31)
{
throws new IllegalArgumentException("Wrong");
}
year=y;
month=m;
day=d;
String s=String.valueOf(year)+'-'+String.valueOf(month)+'-'+String.valueOf(day);
return s;
}
public static void main(String []args)
{
Test t=new Test();
String s;
try
{
s=t.setDay(2001,1,100);
}
catch(IllegalArgumentException e)
{
System.out.println(e.printStackTrace());
}
System.out.println(s);
}
}