What is the output from the following code
public class Main { static { throw new Exception("my exception"); System.out.println("2"); } public static void main(String[] args) { System.out.println("1"); } }
throw new Exception("my exception");//compile time error
You cannot throw a checked exception from a static initializer.
A static initializer must handle all possible checked exceptions that it may throw.