一 代码
package GPer;
public class Test
{
public static void main( String[] args ) {
GPer gper = GPer.getInstance();
Teacher tom = new Teacher("Tom");
Teacher mic = new Teacher("Tim");
gper.addObserver(tom);
gper.addObserver(mic);
Question question = new Question();
question.setUsername("小明");
question.setContent("观察者设计模式适用于哪些场景?");
gper.publishQuestion(question);
int a = 1;
if(a == 1)
{
throw new IndexOutOfBoundsException();
}
System.out.println("打印");
}
}
二 运行结果
小明在GPer生态圈上提交了一个问题。
Exception in thread "main" java.lang.IndexOutOfBoundsException
==============================
at GPer.Test.main(Test.java:18)
Tim老师,你好!
您收到一个来自GPer生态圈的提问,希望您解答,问题内容如下
观察者设计模式适用于哪些场景?
提问者:小明
==============================
Tom老师,你好!
您收到一个来自GPer生态圈的提问,希望您解答,问题内容如下
观察者设计模式适用于哪些场景?
提问者:小明
Process finished with exit code 1
三 问题分析
程序运行抛出IndexOutOfBoundsException这个异常,下面我们通过异常调试的方式找到这行代码。
四 操作步骤
步骤1:
步骤2:
步骤3:
步骤4:
直接debug调试
步骤5:
程序自动找到抛出异常的断点
五 异常调试意义
对于线上抛出异常的问题,采用这种方式,可以很快找到抛出异常的地方。