本帖最后由 java2000_net 于 2008-08-04 16:51:08 编辑

解决方案 »

  1.   

    上面的源码没注意格式,重新发一遍。
    class MyException extends Exception {
    private int id;
    public MyException(String message, int id){
    super(message);
    this.id = id;
    }
    public int getId(){
    return id;
    }
    }public class TestMyException{
    public static void regist(int num) throws MyException{
    if(num<0){
    throw new MyException("num is errorous",3);
    }
    System.out.println("The number of registion is :"+num);
    }
    public static void main(String[] args) throws Exception{
    try{
    regist(-1);
    }catch(MyException e){
    System.out.println("The code of error is:"+e.getId());
    //Thread.sleep(1000);
    e.printStackTrace();
    }
    System.out.println("Operation is over");
    }
    }
      

  2.   

    我的问题就是为什么是不固定的,难道异常又用了一个线程?还是有其他原因?否则感觉应该是按照顺序执行,先打印"The code of error is:3”,然后打印异常信息,这以后还得打印“Operation is over",但顺序总是在变化。为啥?
      

  3.   

    异常使用err的,正常打印是用out的。
    流不一样。