Skip to content

Files

Latest commit

 

History

History
24 lines (14 loc) · 730 Bytes

no_throwing_strings.md

File metadata and controls

24 lines (14 loc) · 730 Bytes

Pattern: Throwing plain string

Issue: -

Description

This rule forbids throwing string literals or interpolations. While JavaScript (and CoffeeScript by extension) allow any expression to be thrown, it is best to only throw Error objects, because they contain valuable debugging information like the stack trace.

Because of JavaScript's dynamic nature, CoffeeLint cannot ensure you are always throwing instances of Error. It will only catch the simple but real case of throwing literal strings.

Examples

# CoffeeLint will catch this:
throw "error text"


# ... but not this:
throw getSomeString()

Further Reading