结论: 如果判断条件非法,直接抛出异常
throw new IllegalArgumentException("Wrong!");
下面直接截取详细内容:
If the program ever executes a statement like:
throw new ???Exception("… message …");
Java stops the program and signals the error through the constructed instance of the ???Exception (where the ??? are replaced by the name of whichever particular exception is desired). For our purposes, this will simply terminate the program and print the given error message.
本文深入探讨了Java中异常处理的基本原理。当程序遇到错误时如何通过抛出特定类型的异常来终止程序并显示错误信息。文章重点讲解了使用throw关键字抛出IllegalArgumentException的具体应用场景。

被折叠的 条评论
为什么被折叠?



