Lab_6

来源:互联网 发布:在淘宝卖宠物用品 编辑:程序博客网 时间:2024/06/10 03:01

趁还没忘...赶紧记下lab_6的要点。

如果,main调用A,A调用B,B调用C。如下所示。

main method  --> mthod_A  --> method_B --> method_C

结果你在C里预判到了错误,并且写了个throw把它throw出来,你在B里不想管,你在A里也不想管,一路throw上去,throw到main,main里不得不handle!

并且在A,B的method declaration里面,还要加上throw这个exception的字眼,表明其,throwable。

在main函数里,你可以一次handle多个报错,比如print error message即可。

这就是本次lab的精髓...

以下是main函数里,catch住多个exceptions,不如错误卡号,错误amount,操作即是print出error message即可。error message我们也写好并且传给super class:Exception即可。err即调用了此信息。

catch (IOException | BadAccountException | BadTransactionException e) {System.err.println(e);}


原创粉丝点击