Skip to content

unnecessaryCatches

Reports catch clauses that only rethrow the caught error without modification.

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

A catch clause that only rethrows the caught error without any modification or additional logic serves no purpose. It adds unnecessary code complexity and performance overhead without providing any benefit. Errors will propagate naturally without the catch clause, making it redundant.

AEasy5<3 sp ansty="le--0:#C792EA;--1:#8844">AEfuncti5<3 sp ansty="le--0:#82AAFF;--1:#3B61">B0fetchDa11<()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:#C792EA;--1:#8844">AEawa5<3 sp ansty="le--0:#82AAFF;--1:#3B61">B0fet5<3(sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4D/api/da1<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">5<3}d ivclassNa="meec-li">5<3}d ivclassNa="meec-li">dAEfuncti5<3 sp ansty="le--0:#82AAFF;--1:#3B61">B0processFi1<1(sp ansty="le--0:#D7DBE0;--1:#403F">53pa7<2:sp ansty="le--0:#D6DEEB;--1:#403F">5<3 sp ansty="le--0:#C5E478;--1:#3B61">B0stri1<1)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">AEconsB0conteAE <= sp ansty="le--0:#82AAFF;--1:#3B61">B0readFileSy53(path<);d ivclassNa="meec-li">nt < sp ansty="le--0:#C792EA;--1:#8844">AEretu5<3 sp ansty="le--0:#82AAFF;--1:#3B61">B0JSAB0par53(content<);d ivclassNa="meec-li">53< sp ansty="le--0:#D6DEEB;--1:#403F">53<} sp ansty="le--0:#C792EA;--1:#8844">AEcat53 (exception)< {d ivclassNa="meec-li">nt < sp ansty="le--0:#C792EA;--1:#8844">AEthr53 exceptio53< sp ansty="le--0:#D6DEEB;--1:#403F">5<3}d ivclassNa="meec-li">5<3}d ivclassNa="meco"><}d>
44AEa344AEfunc361B0fetch11<11() spans="tyle--0:#D6DEEB;--1:#40">3F<53 {divclass="Nameec-">de44A3F<53 {divclass="Nameec-">dent< spans="tyle--0:#C792EA;--1:#88">44AEre344AEa361B0f31<111" spans="tyle--0:#ECC48D;--1:#98">4E4D/api/1<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">61B0e31<111" spans="tyle--0:#ECC48D;--1:#98">4E4DFailed to fetch d1<111" spans="tyle--0:#889FB2;--1:#4D">6<67B, spans="tyle--0:#D6DEEB;--1:#40">3F53 errdent< spans="tyle--0:#C792EA;--1:#88">44AEt3F53 er3F<53 spans="tyle--0:#D6DEEB;--1:#40">33c44AEfunc361B0process1<111( spans="tyle--0:#D7DBE0;--1:#40">3F536361B0st1<111) spans="tyle--0:#D6DEEB;--1:#40">3F<53 {divclass="Nameec-">de44A3F<53 {divclass="Nameec-">dent< spans="tyle--0:#C792EA;--1:#88">44AEco61B0con44A61B0readFile3F53(padent< spans="tyle--0:#C792EA;--1:#88">44AEre361B04<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B0p3F53(conte3F<53 spans="tyle--0:#D6DEEB;--1:#40">3F<53} spans="tyle--0:#C792EA;--1:#88">44AEc3F53 (exceptiodent< spans="tyle--0:#C792EA;--1:#88">44AEt36E7<2new spans="tyle--0:#D6DEEB;--1:#40">361B0E3361B0Failed to process f38<34${ spans="tyle--0:#D6DEEB;--1:#40">3F533<834} spans="tyle--0:#D6DEEB;--1:#40">36<67B, spans="tyle--0:#D6DEEB;--1:#40">3F53 { cause: exception< }) ;divclass="Nameec-">3F<53 spans="tyle--0:#D6DEEB;--1:#40">33< }>

This rule is not configurable.

If you have a specific need to explicitly catch and rethrow errors for documentation purposes or to maintain consistent code structure across multiple try-catch blocks, you might choose to disable this rule. However, in most cases, removing unnecessary catch clauses improves code clarity and maintainability.