Java by API/java.lang/UncaughtExceptionHandler
Версия от 17:43, 31 мая 2010; (обсуждение)
implements UncaughtExceptionHandler
import java.util.ArrayList;
public class Main implements Runnable {
static class OverrideExceptionHandler implements Thread.UncaughtExceptionHandler {
public void uncaughtException(Thread t, Throwable e) {
alertAdministrator(e);
}
}
public static void alertAdministrator(Throwable e) {
// Use Java Mail to send the administrator"s pager an email
System.out.println("Adminstrator alert!");
e.printStackTrace();
}
public static void main(String[] args) {
Thread t = new Thread(new Main());
t.setUncaughtExceptionHandler(new OverrideExceptionHandler());
System.out.println(t.getUncaughtExceptionHandler());
t.start();
}
public void run() {
ArrayList al = new ArrayList();
while (true) {
al.add(new byte[1024]);
}
}
}