A compiler rau Java programming lus kuaj xyuas, ntawm lub sijhawm sau, uas qhov kev zov me nyuam muaj cov neeg ua haujlwm rau kev kuaj xyuas, los ntawm kev txheeb xyuas qhov kev txheeb xyuas qhov kev zam tuaj yeem tshwm sim los ntawm kev ua tiav ntawm txoj kev lossis tus tsim. Rau txhua qhov kev kuaj xyuas uas yog qhov tshwm sim tau, qhov cuam tshuam rau txoj kev (§8.4.
Compiler paub li cas tias hom kev zam tshwm sim?
Thaum muaj kev zam tshwm sim hauv koj qhov kev zov me nyuam, catch blocks raug tshuaj xyuas los ntawm sab saum toj mus rau hauv qab txhawm rau nrhiav qhov sib tw ntawm hom kev zam tshwm sim thiab hom kev zam uas tus catch block yog tuav.
Yuav kuaj xyuas cov kev zam li cas ntawm lub sijhawm sau?
2 Teb. Txheeb xyuas cov kev zam raug kuaj xyuas ntawm lub sijhawm sib sau kom paub tseeb tias koj tau tuav lawv, txawm tiaslos ntawm kev ntes lawv lossis tshaj tawm cov txheej txheem uas cuam tshuam qhov kev zam Thaum lub sijhawm khiav, tsis muaj qhov sib txawv ntawm kev txheeb xyuas thiab tsis tau txheeb xyuas: lawv raug kho zoo ib yam los ntawm JVM.
Kuv yuav ua li cas thiaj nrhiav tau qhov kev zam?
- txheeb xyuas qhov tshwj xeeb yog kuaj los ntawm tus sau thiab ua tus programmer koj yuav tsum tau lis nws siv sim-catch-thaum kawg, ntuav.
- qhov kev zam tsis tau txheeb xyuas tsis tau txheeb xyuas los ntawm cov neeg sau ntawv tab sis koj xaiv tau tuaj yeem tswj hwm nws meej.
Yuav kuaj xyuas cov kev zam tuaj yeem ntes tau?
3 Teb. Unchecked kev zam yog cov kev zam uas tsis tas yuav raug ntes hauv kev sim - ntes thaiv. Unchecked exceptions yog subclasses ntawm RuntimeException los yog yuam kev chav kawm. Kev kuaj xyuas yog qhov tshwj xeeb uas yuav tsum tau ntes hauv qhov sim - ntes thaiv.