class a
{
int ab(int a,int b)
{
if(a<0)throw new b("cuo la");
return a+b;
}
public static void main(String [] args)
{
a wo=new a();
System.out.println(wo.ab(2,3));
}
}
class b extends Exception
{
b(String str)
{
super(str);
}
}
哪错了 ? 抛出异常不可以这样用吗?
{
int ab(int a,int b)
{
if(a<0)throw new b("cuo la");
return a+b;
}
public static void main(String [] args)
{
a wo=new a();
System.out.println(wo.ab(2,3));
}
}
class b extends Exception
{
b(String str)
{
super(str);
}
}
哪错了 ? 抛出异常不可以这样用吗?
{
int ab(int a,int b) throws B
{
if(a <0)
throw new B("cuo la");
return a+b;
}
public static void main(String [] args)
{
A wo=new A();
try {
System.out.println(wo.ab(2,3));
} catch (B e) {
e.printStackTrace();
}
}
}
class B extends Exception
{
B(String str)
{
super(str);
}
}
public static void main(String [] args) throws Exception
{
A wo=new A();
try {
System.out.println(wo.ab(2,3));
} catch (B e) {
e.printStackTrace();
}
}
{
A wo=new A();
System.out.println(wo.ab(2,3));
}
{
A wo=new A();
try {
System.out.println(wo.ab(2,3));
} catch (B e) {
e.printStackTrace();
}
}
也行 嘎嘎