public class add { public static void main(String[] args) { add a=new add(); a.saveabc(1);//提示错误,我该如何修正这个错误 } public int saveabc(int a) throws Exception {
没有捕获异常呗既然你的方法引发了异常,在调用需要捕获或者继续throws Exception public int saveabc(int a) throws Exceptionpublic static void main(String[] args) { add a=new add(); try { a.saveabc(1);//提示错误,我该如何修正这个错误 } catch (Exception ex)//需要捕获该方法抛出的异常 { } }
你的方法既然是这样声明的,就不用再在这个方法中捕获异常了 public int saveabc(int a) throws Exception如果你在这个方法捕获了异常也就不用再throws向上抛异常了 你这样的写法没有任何意义可这样: public int saveabc(int a) throws Exception {
try{ System.out.print("d");
}catch(Exception e){ throw new Exception(ex.toString()); } return a; } 也可这样: public int saveabc(int a) {
public class add { public static void main(String[] args) { add a=new add(); int c=a.saveabc(1);//提示错误,我该如何修正这个错误 } public int saveabc(int a) throws Exception { int b=a; try{ System.out.print("d");
import java.io.*; public class add { public static void main(String[] args) throws Exception { add a=new add(); int b=a.saveabc(1);//提示错误,我该如何修正这个错误 } public int saveabc(int a) {
public int saveabc(int a) throws Exceptionpublic static void main(String[] args) {
add a=new add();
try
{
a.saveabc(1);//提示错误,我该如何修正这个错误
}
catch (Exception ex)//需要捕获该方法抛出的异常
{
}
}
public int saveabc(int a) throws Exception如果你在这个方法捕获了异常也就不用再throws向上抛异常了
你这样的写法没有任何意义可这样:
public int saveabc(int a) throws Exception
{
try{
System.out.print("d");
}catch(Exception e){
throw new Exception(ex.toString());
}
return a;
} 也可这样:
public int saveabc(int a) {
try{
System.out.print("d");
}catch(Exception e){
System.out.print("dd");
}
return a;
}
add a=new add();
a.saveabc(1);//提示错误,我该如何修正这个错误
}
~~~~~~~~~~~~~~~~
public static void main(String[] args) {
add a=new add();
int c=a.saveabc(1);//提示错误,我该如何修正这个错误
} public int saveabc(int a) throws Exception
{
int b=a;
try{
System.out.print("d");
}catch(Exception e){
System.out.print("dd");
}
return b;
}
}
public class add {
public static void main(String[] args) throws Exception
{
add a=new add();
int b=a.saveabc(1);//提示错误,我该如何修正这个错误
} public int saveabc(int a)
{
try{
System.out.print("d");
}catch(Exception e){
System.out.print("dd");
}
return a;
}
}
这样就好了