我写了两段代码:
class MyException extends Exception{
private int detail;
protected void MyException(int a){
detail=a;
}
public String toString(){
return "MyException "+detail;
}
}
和
public class ExceptionDemo{
static void compute(int b) throws MyException{
System.out.println( "called compute( "+b+ ") ");
if(b> 0) throw (new MyException(b));
System.out.println( "normal exit ");
}
public static void main(String args[]){
try{
compute(1);
compute(20);
}
catch(MyException e){
System.out.println( "Caught "+e);
}
}
}
后面的要用到前面编译好的class,我编译第二段的时候总是出错.说MyException找不到,请问各位我该如何处理.谢谢了
------解决方案--------------------
把这两个类都放在同一个目录下,就行了! 而且注意你的classpath里面要有.也就是当前目录