$ javac TestExceptions.java
TestExceptions.java:11: cannot find symbol
symbol : class test
location: class TestExceptions
throw new TestExceptions.test("If you see me, exceptions work!");
^
1 error
代碼的Java:定製異常錯誤
import java.util.*;
import java.io.*;
public class TestExceptions {
static void test(String message) throws java.lang.Error{
System.out.println(message);
}
public static void main(String[] args){
try {
// Why does it not access TestExceptions.test-method in the class?
throw new TestExceptions.test("If you see me, exceptions work!");
}catch(java.lang.Error a){
System.out.println("Working Status: " + a.getMessage());
}
}
}
當將返回類型改爲String時,我得到了同樣的錯誤。 – hhh 2010-04-13 16:38:58
這是因爲'String'不是'Throwable'。看到我答案的第二句話。 – danben 2010-04-13 16:39:14