Java - What is the output: Checked Exceptions and static Initializers

Question

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");
  }
}


Click to view the answer

throw new Exception("my exception");//compile time error

Note

You cannot throw a checked exception from a static initializer.

A static initializer must handle all possible checked exceptions that it may throw.