Eclipse在Debug时手动抛出异常

try {
    Thread.sleep(100);
} catch (InterruptedException e) {
    e.printStackTrace();
    System.out.println("catched");
}

    以上代码中Thread.sleep(100)发生InterruptedException异常的情况很难模拟,可以通过Debug时手动抛出。方法如下:在Thread.sleep()处打断点,Debug,在程序步进到这行时,在Variables窗口中选中某对象,在输入框中输入throw new  InterruptedException();选中后执行Execute,可手动抛出异常,如下图:

#如果没有正常catch语句没有catch到手动抛出的异常,可在catch语句处再添加断点。 

posted @ 2013-03-18 21:44  yldjoy  阅读(1709)  评论(0编辑  收藏  举报