2:56 am - Friday April 19, 2019

Thread Example Program for setUncaughtExceptionHandler(Thread.UncaughtExceptionHandler eh)

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

/**

*@author:candidjava.com
*@description:Thread example program for setUncaughtExceptionHandler(Thread setUncaughtExceptionHandler eh)
*/

public class java
{
public static void main(String[] args) {
Thread trd = new Thread(new examThread());
trd.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {

public void uncaughtException(Thread tr, Throwable er) {
System.out.println(tr + " throws exception: " + er);
}
});

trd.start();
}
}

class examThread implements Runnable {

public void run() {
throw new RuntimeException();
}
}

OUTPUT:

Thread[Thread-0,5,main] throws exception: java.lang.RuntimeException

Filed in: Z-A All Java Codes

Comments are closed.