Thread: getUncaughtExceptionHandler() : Thread « java.lang « Java by API






Thread: getUncaughtExceptionHandler()

  

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

   
    
  








Related examples in the same category

1.Thread.MAX_PRIORITY
2.Thread.NORM_PRIORITY
3.new Thread(Runnable target, String name)
4.Thread.activeCount()
5.Thread.currentThread()
6.Thread.dumpStack()
7.Thread.enumerate(Thread[] tarray)
8.Thread: getStackTrace()
9.Thread: getThreadGroup()
10.Thread: interrupt()
11.Thread: isAlive()
12.Thread: isDaemon()
13.Thread: join() (Using join() to wait for threads to finish)
14.Thread: run()
15.Thread: setDaemon(boolean b)
16.Thread: setDefaultUncaughtExceptionHandler(UncaughtExceptionHandler eh)
17.Threah.sleep(long millis)
18.Thread: setDaemon(boolean on)
19.Thread: setName(String name)
20.Thread: setPriority(int newPriority)
21.Thread: setUncaughtExceptionHandler(UncaughtExceptionHandler eh)
22.Thread: start
23.Thread: stop
24.implements UncaughtExceptionHandler