// 独自の例外クラス
class MyException extends Exception{
public MyException(){
super();
}
}
public class Test{
public static void main(String args[]){
try{
a();
}catch(MyException e){
System.err.println("e");
}
}
public static void a(){
throw new MyException();
}
}
|
// 独自の例外クラス
class MyException extends RuntimeException{
public MyException(){
super();
}
}
public class Test{
public static void main(String args[]){
try{
a();
}catch(MyException e){
System.err.println(e);
}
}
public static void a(){
throw new MyException();
}
}
|
C:\java>javac Test.java
Test.java:11: Exception MyException is never thrown
in the body of the corresponding try statement.
}catch(MyException e){
^
Test.java:17: Exception MyException must be caught,
or it must be declared in the throws clause of this method.
throw new MyException();
^
2 errors
C:\java>
|
C:\java>javac Test.java
C:\java>
|