java异常问题
1///
package sim;
public class NeedCleanup {
private static long counter=1;
private final long id = counter++;
public void dispose(){
System.out.println("NeedsCleanup"+id+"dispised");
}
}
class ConstructionException extends Exception{}
class NeedCleanup2 extends NeedCleanup{
public NeedCleanup2() throws ConstructionException{}
}
2///
package sim;
public class CleanIdiom {
public static void main(String[] args) {
NeedCleanup nc1 = new NeedCleanup();
try{
}finally{
nc1.dispose();
}
NeedCleanup nc2 = new NeedCleanup();
NeedCleanup nc3 = new NeedCleanup();
try{
}finally{
nc3.dispose();
nc2.dispose();
}
try{
NeedCleanup2 nc4 = new NeedCleanup2();
try{
NeedCleanup2 nc5 = new NeedCleanup2();
try{
}finally{
nc5.dispose();
}
}catch(ConstructionException e){
System.out.println(e);
}finally{
nc4.dispose();
}
}catch(ConstructionException e){
System.out.println(e);
}
}
}
看不懂这个,跑单步也看不懂,求网友们解释一下,谢谢了。
package sim;
public class NeedCleanup {
private static long counter=1;
private final long id = counter++;
public void dispose(){
System.out.println("NeedsCleanup"+id+"dispised");
}
}
class ConstructionException extends Exception{}
class NeedCleanup2 extends NeedCleanup{
public NeedCleanup2() throws ConstructionException{}
}
2///
package sim;
public class CleanIdiom {
public static void main(String[] args) {
NeedCleanup nc1 = new NeedCleanup();
try{
}finally{
nc1.dispose();
}
NeedCleanup nc2 = new NeedCleanup();
NeedCleanup nc3 = new NeedCleanup();
try{
}finally{
nc3.dispose();
nc2.dispose();
}
try{
NeedCleanup2 nc4 = new NeedCleanup2();
try{
NeedCleanup2 nc5 = new NeedCleanup2();
try{
}finally{
nc5.dispose();
}
}catch(ConstructionException e){
System.out.println(e);
}finally{
nc4.dispose();
}
}catch(ConstructionException e){
System.out.println(e);
}
}
}
看不懂这个,跑单步也看不懂,求网友们解释一下,谢谢了。
...全文
相关推荐
JAVA基础测试中常见的异常问题汇总-Java-CSDN
在Java编程语言中,异常处理是一项至关重要的技能,尤其是在进行基础测试时。本文将深入探讨在JAVA基础测试中常见的异常问题,帮助开发者更好地理解和解决这些问题。1.
JAVA基础测试中常见的异常问题汇总
在Java编程语言中,异常处理是确保代码健壯性和稳定性的关键部分。下面将深入探讨在Java基础测试中常见的异常问题及其解决方案,尤其关注那些在执行基本Java程序时可能遇到的异常情况。### 1.
java 异常 问题收集 Exception
通过对这些文档《java web 开发问题总结》的深入学习,我们可以更好地理解和解决实际开发中遇到的Java异常问题,提升代码质量,确保应用程序的稳定运行。
Java中关于子类覆盖父类的抛出异常问题
在Java编程语言中,子类覆盖父类的方法时,关于异常处理有特定的规定。这个问题的核心是子类在重写父类方法时抛出异常的规则。
实例解决Java异常之OutOfMemoryError的问题
Java异常解决之OutOfMemoryErrorJava 中的 OutOfMemoryError 异常是指 Java 虚拟机在运行时无法申请到足够的内存空间,导致程序崩溃的错误。


