Java 从静态块抛出已检查异常

Java 从静态块抛出已检查异常,java,static-block,checked-exceptions,Java,Static Block,Checked Exceptions,当我尝试出现以下编译错误时,我想从静态块抛出checked exception: error: unreported exception Exception; must be caught or declared to be thrown 我的静态代码块如下所示: static{ if(something) doSomething(); else throw new Exception("Checked Exception from static block"); }

当我尝试出现以下编译错误时,我想从静态块抛出checked exception:

error: unreported exception Exception; must be caught or declared to be thrown
我的静态代码块如下所示:

static{
if(something)
    doSomething();
else
    throw new Exception("Checked Exception from static block");   

}

如果java中不允许这样做,我可以做些什么来从静态块抛出一个检查过的异常,换句话说,在调用main方法之前我该如何做?谢谢。

简短的回答是:不允许从静态块抛出检查异常

关于您的解决方案请求,没有一个不是黑客。我想发布长答案,但后来我看到您将其标记为重复。。。这就是为什么我停止了简短的回答;-)如果未选中异常类型,则允许此选项。是的。。。我说的只是检查过的异常