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

java catch 话语

2012-12-20 
java catch 语句public class Test{public static void main(String[] args){Test t new Test()t.show(

java catch 语句
public class Test  
{  
    public static void main(String[] args)  
    {  
        Test t = new Test();  
        t.show();  
    }  
      
    public void show()  
    {  
        int a = 0;  
          
        while(true)  
        {  
            try 
            {  
                if(a++ == 0)  
                    throw new MyException();  
                  
                System.out.println("No Exception");  
                  
            }catch(MyException e)  
            {  
                System.out.println("MyException");  
            }catch(Exception e)  
            {  
                System.out.println("Exception");  
            }finally 
            {  
                System.out.println("Finally");  
                  
                if(a == 2)  
                    break;  
            }  
        }  
    }  
}  
 
class MyException extends Throwable  
{  
    private static final long serialVersionUID = -2022776205202627089L;  
      
}








输出为:

MyException  
Finally  
No Exception  
Finally 

热点排行