먼저 다음을 읽어야합니다. http://docs.oracle.com/javase/tutorial/essential/exceptions/index.html! 내가 오류 메시지가 나에게 힌트의 몇 가지 유형을주고 있으리라 믿고있어throwable가 컴파일되지 않음
TestException.java:14: error: incompatible types
static void doRisky(String test) throws ScaryException
^
required: Throwable
found: ScaryException
TestException.java:19: error: incompatible types
throw new ScaryException();
^
required: Throwable
found: ScaryException
TestException.java:34: error: incompatible types
catch (ScaryException se)
^
required: Throwable
found: ScaryException
3 errors
,하지만 난 그냥이 무엇인지 표시되지 않습니다 :
내가 컴파일 할 때 내가 오류는 다음과 .
import java.lang.*;
/** add this as to get it to compile */
class ScaryException extends Exception
{
/** how come I can't put code here? */
}
public class TestException {
static void doRisky(String test) throws ScaryException{
System.out.println ("start risky");
if ("yes".equals(test)) {
throw new ScaryException();
}
System.out.println("end risky");
}
public static void main(String [] args){
String test = "no";
try{
System.out.println("start try");
doRisky(test);
doRisky("yes");
System.out.println("end try");
}
catch (ScaryException se){
System.out.println("Got What " + se);
}
finally{
System. out. println("finally") ;
}
System.out.println("end of main");
}
}
'ScaryException'가 throwable의 서브 클래스를 확장합니까? 보통'java.lang.Exception'인가? – PermGenError