所以,深入了解java中try-catch语句的基础知识.我仍然对语法中的一些差异感到困惑.这是我试图分析和理解的代码.另外,使用try then catch(Exception e)与说只是抛出...或者抛出新的...之间的区别...根据我的理解,try catch基本上是一种通过输出消息或传递来处理错误的方法另一种方法.但是,我认为我坚持它的语法方面.任何建设性的评论或简单的例子都是受欢迎的人.关于这个概念的一些澄清以及我的书中的示例代码的内容将会受到赞赏.
/* Invalid radius class that contains error code */
public class InvalidRadiusException extends Exception {
private double radius;
/** Construct an exception */
public InvalidRadiusException(double radius) {
super("Invalid radius " + radius);
this.radius = radius;
}
/** Return the radius */
public double getRadius() {
return radius;
}
}
public class CircleWithException {
/** The radius of the circle */
private double radius;
/** The number of the objects created */
private static int numberOfObjects …Run Code Online (Sandbox Code Playgroud)