0

i want to throw checked exception from a static block, when i tried that the following compilation error arises:

error: unreported exception Exception; must be caught or declared to be thrown

my static code block is as follows:

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

}

IF this is not allowed in java, what work around can i do to throw a checked exception from a static block,in other word, how can i do that before the main method is called? thanks.

Eslam Hamdy
  • 7,126
  • 27
  • 105
  • 165

1 Answers1

0

Short answer is : Throwing checked exception from static block is not allowed

Pras
  • 1,068
  • 7
  • 18