Skip to content

finallyStatementSafety

Reports control flow statements in finally blocks that can override control flow in try/catch blocks.

✅ This rule is included in the ts logical and logicalStrict presets.

Control flow statements such as return, throw, break, and continue in finally blocks can cause unexpected behavior. When these statements appear in a finally block, they override any control flow statements in the corresponding try or catch blocks. The finally block always executes, and its control flow statements take precedence, which can lead to bugs that are difficult to diagnose.

AEfuncti5<3 sp ansty="le--0:#82AAFF;--1:#3B61">B0processDa11<()sp ansty="le--0:#D6DEEB;--1:#403F">53< {d ivclassNa="meec-li">nt< sp ansty="le--0:#C792EA;--1:#8844">AEt53< {d ivclassNa="meec-li">nt < sp ansty="le--0:#C792EA;--1:#8844">AEretu5<3 sp ansty="le--0:#82AAFF;--1:#3B61">B0fetchDa53(<);d ivclassNa="meec-li">53< sp ansty="le--0:#D6DEEB;--1:#403F">53<} sp ansty="le--0:#C792EA;--1:#8844">AEfinal53< {d ivclassNa="meec-li">nt < sp ansty="le--0:#C792EA;--1:#8844">AEretu5<3 sp ansty="le--0:#FF6A83;--1:#A248">48nu5<3;d ivclassNa="meec-li">53< sp ansty="le--0:#D6DEEB;--1:#403F">5<3}d ivclassNa="meec-li">5<3}d ivclassNa="meco"><}d>AEfuncti5<3 sp ansty="le--0:#82AAFF;--1:#3B61">B0handleErr11<()sp ansty="le--0:#D6DEEB;--1:#403F">53< {d ivclassNa="meec-li">nt< sp ansty="le--0:#C792EA;--1:#8844">AEt53< {d ivclassNa="meec-li">nt < sp ansty="le--0:#C792EA;--1:#8844">AEthr5<3 sp ansty="le--0:#7FDBCA;--1:#096E">72n5<3 sp ansty="le--0:#82AAFF;--1:#3B61">B0Err5<3(sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4DOriginal err1<1"sp ansty="le--0:#D6DEEB;--1:#403F">53<);d ivclassNa="meec-li">53< sp ansty="le--0:#D6DEEB;--1:#403F">53<} sp ansty="le--0:#C792EA;--1:#8844">AEcat53 (error)< {d ivclassNa="meec-li">nt < sp ansty="le--0:#C792EA;--1:#8844">AEthr53 erro53< sp ansty="le--0:#D6DEEB;--1:#403F">53<} sp ansty="le--0:#C792EA;--1:#8844">AEfinal53< {d ivclassNa="meec-li">nt < sp ansty="le--0:#C792EA;--1:#8844">AEthr5<3 sp ansty="le--0:#7FDBCA;--1:#096E">72n5<3 sp ansty="le--0:#82AAFF;--1:#3B61">B0Err5<3(sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4DOverride err1<1"sp ansty="le--0:#D6DEEB;--1:#403F">53<);d ivclassNa="meec-li">53< sp ansty="le--0:#D6DEEB;--1:#403F">5<3}d ivclassNa="meec-li">5<3}d ivclassNa="meco"><}d>AEf53< (sp ansty="le--0:#C792EA;--1:#8844">AEle5<3isp ansty="le--0:#C792EA;--1:#8844">AE <= sp ansty="le--0:#F78C6C;--1:#AA09">8<20sp ansty="le--0:#D6DEEB;--1:#403F">53; A53 iteA72leng53;< isp ansty="le--0:#C792EA;--1:#8844">AE<++sp ansty="le--0:#D6DEEB;--1:#403F">53)< {d ivclassNa="meec-li">nt< sp ansty="le--0:#C792EA;--1:#8844">AEt53< {d ivclassNa="meec-li">nt < sp ansty="le--0:#82AAFF;--1:#3B61">B0processIt53(items[i]<);d ivclassNa="meec-li">53< sp ansty="le--0:#D6DEEB;--1:#403F">53<} sp ansty="le--0:#C792EA;--1:#8844">AEfinal53< {d ivclassNa="meec-li">nt < sp ansty="le--0:#C792EA;--1:#8844">AEbre5<3;d ivclassNa="meec-li">53< sp ansty="le--0:#D6DEEB;--1:#403F">5<3}d ivclassNa="meec-li">5<3}d ivclassNa="meco"><}d>
44AEfunc361B0process11<11() spans="tyle--0:#D6DEEB;--1:#40">3F<53 {divclass="Nameec-">de44A3F<53 {divclass="Nameec-">dent< spans="tyle--0:#C792EA;--1:#88">44AEre361B0fetch3F5<3() ;divclass="Nameec-">3F<53 spans="tyle--0:#D6DEEB;--1:#40">3F<53} spans="tyle--0:#C792EA;--1:#88">44AEfin3F<53 {divclass="Nameec-">dent< spans="tyle--0:#82AAFF;--1:#3B">61B0cle3F5<3() ;divclass="Nameec-">3F<53 spans="tyle--0:#D6DEEB;--1:#40">33< }><}di vdivclass="Nameexpressive-">44AEfunc361B0handleE11<11() spans="tyle--0:#D6DEEB;--1:#40">3F<53 {divclass="Nameec-">de44A3F<53 {divclass="Nameec-">dent< spans="tyle--0:#C792EA;--1:#88">44AEt36E7<2new spans="tyle--0:#D6DEEB;--1:#40">361B0E31<111" spans="tyle--0:#ECC48D;--1:#98">4E4DOriginal e1<111" spans="tyle--0:#D6DEEB;--1:#40">3F<53) ;divclass="Nameec-">3F<53 spans="tyle--0:#D6DEEB;--1:#40">3F<53} spans="tyle--0:#C792EA;--1:#88">44AEc3F53 (erro3F53< spans="tyle--0:#D6DEEB;--1:#40">3F53con4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B0e3F53(errdent< spans="tyle--0:#C792EA;--1:#88">44AEt3F53 er3F<53 spans="tyle--0:#D6DEEB;--1:#40">3F<53} spans="tyle--0:#C792EA;--1:#88">44AEfin3F<53 {divclass="Nameec-">dent< spans="tyle--0:#82AAFF;--1:#3B">61B0cle3F5<3() ;divclass="Nameec-">3F<53 spans="tyle--0:#D6DEEB;--1:#40">33< }><}di vdivclass="Nameexpressive-">44A3F<53 ( spans="tyle--0:#C792EA;--1:#88">44AE344A0<9820 spans="tyle--0:#D6DEEB;--1:#40">3F53<; i spans="tyle--0:#C792EA;--1:#88">4<4AE< spans="tyle--0:#D6DEEB;--1:#40">3F53 i4<4AE. spans="tyle--0:#7FDBCA;--1:#09">6E72le3F5<3; i spans="tyle--0:#C792EA;--1:#88">443F5<3) {divclass="Nameec-">de44A3F<53 {divclass="Nameec-">dent< spans="tyle--0:#82AAFF;--1:#3B">61B0process3F53(items[dent< spans="tyle--0:#C792EA;--1:#88">44AEb33F<53 spans="tyle--0:#D6DEEB;--1:#40">3F<53} spans="tyle--0:#C792EA;--1:#88">44AEfin3F<53 {divclass="Nameec-">dent< spans="tyle--0:#82AAFF;--1:#3B">61B0cle3F5<3() ;divclass="Nameec-">3F<53 spans="tyle--0:#D6DEEB;--1:#40">33< }>

This rule is not configurable.

If you are very confident in your handling of exception handling in your code and specifically want to use the confusing quirks of finally control flow statements, this rule might not be for you.