Skip to content

Instantly share code, notes, and snippets.

@siosio
Created May 15, 2012 14:25
Show Gist options
  • Save siosio/2702154 to your computer and use it in GitHub Desktop.
Save siosio/2702154 to your computer and use it in GitHub Desktop.
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
public class NewInstanceInConstructor {
public NewInstanceInConstructor() throws Throwable {
// チェック例外を送出する。
throw new IOException();
}
public static void main(String[] args) throws NoSuchMethodException {
invoke();
}
private static void invoke() throws NoSuchMethodException {
Constructor<NewInstanceInConstructor> constructor =
NewInstanceInConstructor.class.getConstructor();
try {
constructor.newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
// 例外が発生するので、ここで補足される。
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment