Skip to content

throwErrors

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">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4DSomething went wro1<1"sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meco"><";d>AEthr53 { message<: sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4Derr1<1"sp ansty="le--0:#D6DEEB;--1:#403F">53, code<: sp ansty="le--0:#F78C6C;--1:#AA09">825<00sp ansty="le--0:#D6DEEB;--1:#403F">53 <};d ivclassNa="meco"><};d>AEthr5<3 sp ansty="le--0:#82AAFF;--1:#3B61">B0undefin5<3;d ivclassNa="meco">
44AEt36E7<2new spans="tyle--0:#D6DEEB;--1:#40">361B0E31<111" spans="tyle--0:#ECC48D;--1:#98">4E4DSomething went w1<111" spans="tyle--0:#D6DEEB;--1:#40">3F<53) ;divclass="Name"><;di vdivclass="Nameexpressive-">44AEc31111HttpE344AEext361B0E3F<53 {divclass="Nameec-">de61B0constru1<111 (divclass="Nameec-">3F53< spans="tyle--0:#D7DBE0;--1:#40">3F53mes6361B0st3dent< spans="tyle--0:#C792EA;--1:#88">44AEpu<3F53 spans="tyle--0:#D6">DDBE06361B0nu3de1<111) spans="tyle--0:#D6DEEB;--1:#40">3F<53 {divclass="Nameec-">dent< spans="tyle--0:#7FDBCA;--1:#09">6E72s3F53(messadent< spans="tyle--0:#7FDBCA;--1:#09">6E724<4AE. spans="tyle--0:#7FDBCA;--1:#09">6E7234<4AE= spans="tyle--0:#D6DEEB;--1:#40">31<111" spans="tyle--0:#ECC48D;--1:#98">4E4DHttpE1<111" spans="tyle--0:#D6DEEB;--1:#40">33F<53 spans="tyle--0:#D6DEEB;--1:#40">3344AEt36E7<2new spans="tyle--0:#D6DEEB;--1:#40">361B0HttpE31<111" spans="tyle--0:#ECC48D;--1:#98">4E4De1<111" spans="tyle--0:#D6DEEB;--1:#40">3F<53, spans="tyle--0:#F78C6C;--1:#AA">098<2500 spans="tyle--0:#D6DEEB;--1:#40">3F<53) ;divclass="Name"><00)>

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.