Java—Throwing Exceptions
一、指定方法引发的异常上一节展示了如何为ListOfNumbers类中的writeList()方法编写异常处理程序。有时,代码捕获可能在其中发生的异常是适当的。然而,在其他情况下,最好让调用堆栈更上层的方法处理该异常。例如,如果您将ListOfNumbers类作为类包的一部分提供,则可能无法预测包中所有用户的需求。在这种情况下,最好不要捕获异常,并允许调用堆栈上更高的方法来处理它。如....

java中的异常--Exceptions in Java-- 第五部分
TemperatureException at VirtualPerson.drinkCoffee(VirtualPerson.java:20) at VirtualCafe.serveCustomer(VirtualC...
java中的异常--Exceptions in Java-- 第四部分
This coffee has an unusual taste. In the UnusualTasteException case, both drinkCoffee() and serveCoffee() methods completed abruptly. The Java virtual machine popped two frames from the Java sta...
java中的异常--Exceptions in Java-- 第三部分
Must enter integer as first argument. Although the above example had only one catch clause, you can have many catch clauses associated with a single try block. Here's an example: // In Source P...
java中的异常--Exceptions in Java-- 第二部分
然而,很多时候,你将希望传达更多的错误信息而不只是一个java.lang中的类。通常这个异常类本身标志遇到这个不正确的情况。例如,如果一个被抛出异常拥有IllegalArgumentException异常。那就标志某些程序通过了一个非法的参数调用了这个方法。有的时候你想要指出一个遇到了非法的条件(这个非法条件没有在java.lang中被定义)的方法。 Other times, howe...
java中的异常--Exceptions in Java-- 第一部分
作者和出处 By Bill Venners, JavaWorld.com http://www.javaworld.com/javaworld/jw-07-1998/jw-07-exceptions.html Exceptions in Java 当一个方法遇到了一个他不能处理的异...
本页面内关键词为智能算法引擎基于机器学习所生成,如有任何问题,可在页面下方点击"联系我们"与我们沟通。
Java开发者
Java开发者成长课堂,课程资料学习,实战案例解析,Java工程师必备词汇等你来~
+关注