Java Exception With Thread Example
Chapter:
Exception Handling
Last Updated:
04-09-2016 16:48:16 UTC
Program:
/* ............... START ............... */
package ExceptionHandling;
class MyThread extends Thread {
public void run() {
System.out.println("Throwing in " + "MyThread");
throw new RuntimeException();
}
}
public class JavaExceptionWithThread {
public static void main(String[] args) {
MyThread t = new MyThread();
t.start();
try {
Thread.sleep(1000);
} catch (Exception x) {
System.out.println("Caught it" + x);
}
System.out.println("Exiting main");
}
}
/* ............... END ............... */
Output
Throwing in MyThread
Exception in thread "Thread-0" java.lang.RuntimeException
at ExceptionHandling.MyThread.run(JavaExceptionWithThread.java:6)
Exiting main
Tags
Java Exception With Thread, Java, Exception Handling