package debug;
public class Test {
static int x = 0;
static String s = "123";
static {
String s1 = "456";
if(1==1)
throw new RuntimeException();
}
public static void main(String[] args) {
new Test();
}
}
To compile it and run it.
java.lang.ExceptionInInitializerError Caused by: java.lang.RuntimeException
at debug.Test.<clinit>(Test.java:8)
Exception in thread "main"
January 15th Thursday 2009 (一月 十五日 木曜日)
最新推荐文章于 2025-09-16 13:06:18 发布
本文介绍了一个Java程序中处理异常的实例。该程序定义了一个包含静态初始化块抛出运行时异常的类,在主方法中创建了该类的实例,导致初始化错误。通过这个例子,读者可以了解如何在Java中处理此类异常。
1329

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



