java 异常出的岔子不是很清楚 请高手们帮帮忙
classMyExceptionextendsException{publicMyException(){}publicMyException(Stringmsg){su...
class MyException extends Exception{
public MyException(){}
public MyException(String msg){super(msg);}
}
public class FullConstructors{
public static void f() throws MyException{
System.out.println("Throwing MyException from g()");
throw new MyException("Originated in g()");
}
public static void main(String args[]){
try{
f();
}catch(MyException e){
e.printStackTrace();
}
try{
g();
}catch(MyException e){
e.printStackTrace();
}
}
}
这个程序编译的时候会出如下的错误
1,FullConstructor.java:4:找不到符号
符号:构造函数 Ecxeption(java.lang.string)
位置:类Exception
public MyException(String msg)(super(msg);)
先谢谢啊 呵呵 我看了我把它改成如下了
import java.lang.*;
class MyException extends Exception{
public MyException(){}
public MyException(String msg){super(msg);}
}
public class FullConstructors{
public static void f() throws MyException{
System.out.println("Throwing MyException from f()");
throw new MyException("Originated in f()");
}
public static void main(String args[]){
try{
f();
}catch(MyException e){
e.printStackTrace();
}
}
但是又出了问题不知道和解啊
1,行4:找不到符号
符号:构造函数 Exception(Java.lang.String)
位置:类Exception
public Myexception(String msg){super(msg);}//指的是super
2,行7:不兼容的类型
找到:MyException
需要:java.lang.Throwable
public static void f() throws MyException{//指MyExcption
还有我的是jdk1.60是不是跟着有关呢 展开
public MyException(){}
public MyException(String msg){super(msg);}
}
public class FullConstructors{
public static void f() throws MyException{
System.out.println("Throwing MyException from g()");
throw new MyException("Originated in g()");
}
public static void main(String args[]){
try{
f();
}catch(MyException e){
e.printStackTrace();
}
try{
g();
}catch(MyException e){
e.printStackTrace();
}
}
}
这个程序编译的时候会出如下的错误
1,FullConstructor.java:4:找不到符号
符号:构造函数 Ecxeption(java.lang.string)
位置:类Exception
public MyException(String msg)(super(msg);)
先谢谢啊 呵呵 我看了我把它改成如下了
import java.lang.*;
class MyException extends Exception{
public MyException(){}
public MyException(String msg){super(msg);}
}
public class FullConstructors{
public static void f() throws MyException{
System.out.println("Throwing MyException from f()");
throw new MyException("Originated in f()");
}
public static void main(String args[]){
try{
f();
}catch(MyException e){
e.printStackTrace();
}
}
但是又出了问题不知道和解啊
1,行4:找不到符号
符号:构造函数 Exception(Java.lang.String)
位置:类Exception
public Myexception(String msg){super(msg);}//指的是super
2,行7:不兼容的类型
找到:MyException
需要:java.lang.Throwable
public static void f() throws MyException{//指MyExcption
还有我的是jdk1.60是不是跟着有关呢 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询