Skip to content

Instantly share code, notes, and snippets.

@siosio
Created May 15, 2012 14:19
Show Gist options
  • Save siosio/2702119 to your computer and use it in GitHub Desktop.
Save siosio/2702119 to your computer and use it in GitHub Desktop.
import java.io.IOException;
public class NewInstanceInClass {
public NewInstanceInClass() throws Throwable {
// チェック例外を送出する。
throw new IOException();
}
public static void main(String[] args) {
invoke();
}
// チェック例外が補足されずに上位にthrowされる。
private static void invoke() {
Class<NewInstanceInClass> clazz = NewInstanceInClass.class;
try {
clazz.newInstance();
} catch (InstantiationException e) {
System.out.println("InstantiationException");
e.printStackTrace();
} catch (IllegalAccessException e) {
System.out.println("IllegalAccessException");
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment