public class Test {
public static void main(String[] args) {
Test test = new Test();
try{
test.method1();
} catch(SomeException e){
e.printStackTrace();
}
}
public void method1() throws SomeException{method2();}

public void method2() throws SomeException{method3();}

public void method3() throws SomeException{
throw new SomeException("SomeException occur in method3");
}
}
 各位大虾帮忙看看哪里有错,编译通不过,我是初学者,请不吝赐教!!

解决方案 »

  1.   

    SomeException是否定义好了呢?有没有构造方法;public SomeException(String str) {super(str)}.
      

  2.   

    老兄你定义SomeException类了吗?
      

  3.   

    不会编译不通过。如果编译不过,只有一个原因: 你的SomeException没有定义Java中如果要用自定义异常,是需要先定义的。。 不能随便乱用的。JDK中没有提供你这个异常,多看下书,看看我给你的代码public class Test {
    public static void main(String[] args) {
    Test test = new Test();
    try {
    test.method1();
    } catch (SomeException e) {
    e.printStackTrace();
    }
    } public void method1() throws SomeException {
    method2();
    } public void method2() throws SomeException {
    method3();
    } public void method3() throws SomeException {
    throw new SomeException("SomeException occur in method3");
    }
    }
    class SomeException extends Exception{
    public SomeException(String msg){
    super(msg);
    }

    public SomeException(Throwable e){
    super(e);
    }
    }
      

  4.   

    [code=Java]
    public class ExceptionTest {
    public static void main(String[] args) {
    ExceptionTest test = new ExceptionTest();
    try{
    test.method1();
    } catch(SomeException e){
    e.printStackTrace();
    }
    }
    public void method1() throws SomeException{method2();} public void method2() throws SomeException{method3();} public void method3() throws SomeException{
    throw new SomeException("SomeException occur in method3");
    }
    }class SomeException extends Exception {
    SomeException(String s) {
    System.out.println(s);
    }
    }
    [/code这是不是你要的? 说实话没看懂你问的是什么
      

  5.   

    你把SomeException定义成这样试一下:public class SomeException extends Exception{

    SomeException() {

    }
    SomeException(String str) {
    super(str);
    }
    }