Reports throwing values that are not Error objects.
✅ This rule is included in the ts logical presets.
Only Error objects (or objects that extend Error) should be thrown.
Throwing non-Error values has several downsides:
- No stack trace information for debugging
- Inconsistent error handling behavior
- Cannot use standard error properties like
cause, message, or name
This rule reports on any throw statement where the value being thrown is not an Error.
AEthr5<3 sp ansty="le--0:#D9F5DD;--1:#1111">13 sp><1"sp ansty="le--0:#ECC48D;--1:#984E">4DSomething went wro1"sp>1<1"sp ansty="le--0:#D6DEEB;--1:#403F">51"sp><3;d ivclassNa="meco"><";d>";d>3;d>AEthr53 { message<: sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4Derr1"sp>1<1"sp ansty="le--0:#D6DEEB;--1:#403F">53, code1"sp><: sp ansty="le--0:#F78C6C;--1:#AA09">825<00sp ansty="le--0:#D6DEEB;--1:#403F">53 00sp><};d ivclassNa="meco"><};d>};d>};d>AEthr5<3 sp ansty="le--0:#82AAFF;--1:#3B61">B0undefin3 sp>5<3;d ivclassNa="meco">3;d> 44AEt36E7<2new spans="tyle--0:#D6DEEB;--1:#40">32new>61B0E31<111" spans="tyle--0:#ECC48D;--1:#98">4E4DSomething went w111">1<111" spans="tyle--0:#D6DEEB;--1:#40">3F111"><53) ;divclass="Name">53)><;di vdivclass="Nameexpressive-">44AEc31111HttpE344AEext361B0E3F<53 {divclass="Nameec-">de61B0constru153 ><111 (divclass="Nameec-">3F53< spans="tyle--0:#D7DBE0;--1:#40">3F53mes >6361B0st3111>dent< spans="tyle--0:#C792EA;--1:#88">44AEpu ><3F53 spans="tyle--0:#D6">D3F53>DBE06361B0nu3de1<111) spans="tyle--0:#D6DEEB;--1:#40">3F111)><53 {divclass="Nameec-">dent< spans="tyle--0:#7FDBCA;--1:#09">6E72s >3F53(messa53 >dent< spans="tyle--0:#7FDBCA;--1:#09">6E72 >4<4AE. spans="tyle--0:#7FDBCA;--1:#09">6E724AE.>34<4AE= spans="tyle--0:#D6DEEB;--1:#40">34AE=>1<111" spans="tyle--0:#ECC48D;--1:#98">4E4DHttpE111">1<111" spans="tyle--0:#D6DEEB;--1:#40">3111">3F<53 spans="tyle--0:#D6DEEB;--1:#40">353 >344AEt36E7<2new spans="tyle--0:#D6DEEB;--1:#40">32new>61B0HttpE31<111" spans="tyle--0:#ECC48D;--1:#98">4E4De111">1<111" spans="tyle--0:#D6DEEB;--1:#40">3F111"><53, spans="tyle--0:#F78C6C;--1:#AA">09853, ><2500 spans="tyle--0:#D6DEEB;--1:#40">3F2500><53) ;divclass="Name"><00)>00)>53)>;di>
This rule is not configurable.
If you’re working with legacy code that throws non-Error values and refactoring would be too costly, you may disable this rule.