全民快乐8

你当前所在位置:全民快乐8 > IT就业问题 > Java面试题及答案(7/19)——异常

Java面试题及答案(7/19)——异常

74. throw 和 throws 的区别?

 

throwsSHIYONGLAISHENGMINGYIGEFANGFAKENENGPAOCHUDESUOYOUYICHANGXINXI,throwsSHIJIANGYICHANGSHENGMINGDANSHIBUCHULI,ERSHIJIANGYICHANGWANGSHANGCHUAN,SHEIDIAOYONGWOJIUJIAOJISHEICHULI。ERthrowZESHIZHIPAOCHUDEYIGEJUTIDEYICHANGLEIXING。

 

75. final、finally、finalize 有什么区别?

 

全民快乐8● finalKEYIXIUSHILEI、BIANLIANG、FANGFA,XIUSHILEIBIAOSHIGAILEIBUNENGBEIJICHENG、XIUSHIFANGFABIAOSHIGAIFANGFABUNENGBEIZHONGXIE、XIUSHIBIANLIANGBIAOSHIGAIBIANLIANGSHIYIGECHANGLIANGBUNENGBEIZHONGXINFUZHI。

 

● finallyYIBANZUOYONGZAItry-catchDAIMAKUAIZHONG,ZAICHULIYICHANGDESHIHOU,TONGCHANGWOMENJIANGYIDINGYAOZHIXINGDEDAIMAFANGFAfinallyDAIMAKUAIZHONG,BIAOSHIBUGUANSHIFOUCHUXIANYICHANG,GAIDAIMAKUAIDOUHUIZHIXING,YIBANYONGLAICUNFANGYIXIEGUANBIZIYUANDEDAIMA。

 

全民快乐8● finalizeSHIYIGEFANGFA,SHUYUObjectLEIDEYIGEFANGFA,ERObjectLEISHISUOYOULEIDEFULEI,GAIFANGFAYIBANYOULAJIHUISHOUQILAIDIAOYONG,DANGWOMENDIAOYONGSystemDEgc()FANGFADESHIHOU,YOULAJIHUISHOUQIDIAOYONGfinalize(),HUISHOULAJI。

 

76. try-catch-finally 中哪个部分可以省略?

 

全民快乐8DA:catch KEYISHENGLVE

 

YUANYIN:

 

GENGWEIYANGEDESHUOFAQISHISHI:tryZHISHIHECHULIYUNXINGSHIYICHANG,try+catchSHIHECHULIYUNXINGSHIYICHANG+PUTONGYICHANG。YEJIUSHISHUO,RUGUONIZHIYONGtryQUCHULIPUTONGYICHANGQUEBUJIAYIcatchCHULI,BIANYISHITONGBUGUODE,YINWEIBIANYIQIYINGXINGGUIDING,PUTONGYICHANGRUGUOXUANZEBUHUO,ZEBIXUYONGcatchXIANSHISHENGMINGYIBIANJINYIBUCHULI。ERYUNXINGSHIYICHANGZAIBIANYISHIMEIYOURUCIGUIDING,SUOYIcatchKEYISHENGLVE,NIJIASHANGcatchBIANYIQIYEJUEDEWUKEHOUFEI。

 

LILUNSHANG,BIANYIQIKANRENHEDAIMADOUBUSHUNYAN,DOUJUEDEKENENGYOUQIANZAIDEWENTI,SUOYINIJISHIDUISUOYOUDAIMAJIASHANGtry,DAIMAZAIYUNXINGQISHIYEZHIBUGUOSHIZAIZHENGCHANGYUNXINGDEJICHUSHANGJIAYICENGPI。DANSHINIYIDANDUIYIDUANDAIMAJIASHANGtry,JIUDENGYUXIANSHIDICHENGNUOBIANYIQI,DUIZHEIDUANDAIMAKENENGPAOCHUDEYICHANGJINXINGBUHUOERFEIXIANGSHANGPAOCHUCHULI。RUGUOSHIPUTONGYICHANG,BIANYIQIYAOQIUBIXUYONGcatchBUHUOYIBIANJINYIBUCHULI;RUGUOYUNXINGSHIYICHANG,BUHUORANHOUDIUQIBINGQIE+finallySAOWEICHULI,HUOZHEJIASHANGcatchBUHUOYIBIANJINYIBUCHULI。

 

ZHIYUJIASHANGfinally,ZESHIZAIBUGUANYOUMEIBUHUOYICHANG,DOUYAOJINXINGDE“SAOWEI”CHULI。

 

77. try-catch-finally 中,如果 catch 中 return 了,finally 还会执行吗?

 

DA:HUIZHIXING,ZAI return QIANZHIXING。

 

DAIMASHILI1:

 

Java面试题异常类

 

ZHIXINGJIEGUO:30

 

DAIMASHILI2:

 

Java面试题异常类

 

ZHIXINGJIEGUO:40

 

78. 常见的异常类有哪些?

 

全民快乐8● NullPointerException:DANGYINGYONGCHENGXUSHITUFANGWENKONGDUIXIANGSHI,ZEPAOCHUGAIYICHANG。

全民快乐8● SQLException:TIGONGGUANYUSHUJUKUFANGWENCUOWUHUOQITACUOWUXINXIDEYICHANG。

● IndexOutOfBoundsException:ZHISHIMOUPAIXUSUOYIN(LIRUDUISHUZU、ZIFUCHUANHUOXIANGLIANGDEPAIXU)CHAOCHUFANWEISHIPAOCHU。

● NumberFormatException:DANGYINGYONGCHENGXUSHITUJIANGZIFUCHUANZHUANHUANCHENGYIZHONGSHUZHILEIXING,DANGAIZIFUCHUANBUNENGZHUANHUANWEISHIDANGGESHISHI,PAOCHUGAIYICHANG。

● FileNotFoundException:DANGSHITUDAKAIZHIDINGLUJINGMINGBIAOSHIDEWENJIANSHIBAISHI,PAOCHUCIYICHANG。

全民快乐8● IOException:DANGFASHENGMOUZHONGI/OYICHANGSHI,PAOCHUCIYICHANG。CILEISHISHIBAIHUOZHONGDUANDEI/OCAOZUOSHENGCHENGDEYICHANGDETONGYONGLEI。

● ClassCastException:DANGSHITUJIANGDUIXIANGQIANGZHIZHUANHUANWEIBUSHISHILIDEZILEISHI,PAOCHUGAIYICHANG。

全民快乐8● ArrayStoreException:SHITUJIANGCUOWULEIXINGDEDUIXIANGCUNCHUDAOYIGEDUIXIANGSHUZUSHIPAOCHUDEYICHANG。

● IllegalArgumentException:PAOCHUDEYICHANGBIAOMINGXIANGFANGFACHUANDILEYIGEBUHEFAHUOBUZHENGQUEDECANSHU。

全民快乐8● ArithmeticException:DANGCHUXIANYICHANGDEYUNSUANTIAOJIANSHI,PAOCHUCIYICHANG。LIRU,YIGEZHENGSHU“CHUYILING”SHI,PAOCHUCILEIDEYIGESHILI。

● NegativeArraySizeException:RUGUOYINGYONGCHENGXUSHITUCHUANGJIANDAXIAOWEIFUDESHUZU,ZEPAOCHUGAIYICHANG。

● NoSuchMethodException:WUFAZHAODAOMOUYITEDINGFANGFASHI,PAOCHUGAIYICHANG。

全民快乐8● SecurityException:YOUANQUANGUANLIQIPAOCHUDEYICHANG,ZHISHICUNZAIANQUANQINFAN。

全民快乐8● UnsupportedOperationException:DANGBUZHICHIQINGQIUDECAOZUOSHI,PAOCHUGAIYICHANG。

● RuntimeExceptionRuntimeException:SHINEIXIEKENENGZAIJavaXUNIJIZHENGCHANGYUNXINGQIJIANPAOCHUDEYICHANGDECHAOLEI。


课程预约

全民快乐8

全民快乐8

全民快乐8

全民快乐8