在用JDK编译的时候,说找不到Exception,但是我用它的基类Throwable代替却可以正常通过。同时必须在开头写import java.lang.Throwable;,不然也无法通过编译。
java.lang这个包不是不用写这个语句,自动加入的吗?
不知道这个问题是怎么产生的,应该怎么解决?
import java.util.*;
import java.lang.Throwable;
abstract class myThrowable extends Throwable
{
abstract public void a();
}
class B92 extends myThrowable
{public void a(){
System.err.println("B92");
}
}
class B93 extends myThrowable
{public void a(){
System.err.println("B93");
}
}
class B94 extends myThrowable
{public void a(){
System.err.println("B94");
}
}
class A97{
public static void g(int type) throws B92,B93,B94{
switch(type){
case 0:throw new B92();
case 1:throw new B93();
case 2:throw new B94();
}
}
public static void main(String[] args)
{
for(int i=0;i<3;i++){
try{
g(i);
}
catch(myThrowable e){
e.a();
}
}
}
}
java.lang这个包不是不用写这个语句,自动加入的吗?
不知道这个问题是怎么产生的,应该怎么解决?
import java.util.*;
import java.lang.Throwable;
abstract class myThrowable extends Throwable
{
abstract public void a();
}
class B92 extends myThrowable
{public void a(){
System.err.println("B92");
}
}
class B93 extends myThrowable
{public void a(){
System.err.println("B93");
}
}
class B94 extends myThrowable
{public void a(){
System.err.println("B94");
}
}
class A97{
public static void g(int type) throws B92,B93,B94{
switch(type){
case 0:throw new B92();
case 1:throw new B93();
case 2:throw new B94();
}
}
public static void main(String[] args)
{
for(int i=0;i<3;i++){
try{
g(i);
}
catch(myThrowable e){
e.a();
}
}
}
}
不过确如你所说,lang包中的类是不用显式的导入的