日期:2014-05-20  浏览次数:20603 次

请问为什么没有打印exception?
Java code
public static void main(String[] args)
 2     {
 3 
 4         try
 5         {
 6             Thread thread = new Thread(){
 7                 @Override
 8                 public void run()
 9                 {  
10                     int i = 0;
11                     System.out.println(2/i);
12                 }
13             };
14             thread.start();
15         }
16         catch (Exception e)
17         {
18             System.out.println("exception");
19         }
20     }


------解决方案--------------------
异常肯定产生了,LZ的程序,主线程中不能捕获到子线程异常。得在子线程中可以捕获

百度一下 java 主线程捕捉子线程异常