首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java相关 >

请教为什么没有打印exception

2012-08-15 
请问为什么没有打印exception?Java codepublic static void main(String[] args) 2{ 34try 5{ 6Thread thr

请问为什么没有打印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 主线程捕捉子线程异常

热点排行