runnable的线程抛出异常无法捕获

阅读 45

2023-03-03


package com.itbuluoge.mythread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

class MyThread implements Runnable
{
public void run()
{
throw new RuntimeException();
}
}
public class ExceptionThread{

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try
{
ExecutorService exec=Executors.newCachedThreadPool();
exec.execute(new MyThread());
}
catch(Exception e)
{
System.out.println("exception");
}

}

}


精彩评论(0)

0 0 举报