debugtypescriptCriticalCanonical
Proper use of errors
Viewed 0 times
propererrorsuse
Problem
I'm using TypeScript for a reasonably large project, and am wondering what the standard is for the use of
Would the equivalent statement in TypeScript be:
What other ways could I accomplish this? What is the accepted standard?
Errors. For example, say I hand an index out of bounds exception in Java:throw new IndexOutOfBoundsException();Would the equivalent statement in TypeScript be:
throw new Error("Index Out of Bounds");What other ways could I accomplish this? What is the accepted standard?
Solution
Someone posted this link to the MDN in a comment, and I think it was very helpful. It describes things like ErrorTypes very thoroughly.
EvalError --- Creates an instance representing an error that occurs regarding the global function eval().
InternalError --- Creates an instance representing an error that occurs when an internal error in the JavaScript engine is thrown. E.g.
"too much recursion".
RangeError --- Creates an instance representing an error that occurs when a numeric variable or parameter is outside of its valid
range.
ReferenceError --- Creates an instance representing an error that occurs when de-referencing an invalid reference.
SyntaxError --- Creates an instance representing a syntax error that occurs while parsing code in eval().
TypeError --- Creates an instance representing an error that occurs when a variable or parameter is not of a valid type.
URIError --- Creates an instance representing an error that occurs when encodeURI() or decodeURI() are passed invalid parameters.
EvalError --- Creates an instance representing an error that occurs regarding the global function eval().
InternalError --- Creates an instance representing an error that occurs when an internal error in the JavaScript engine is thrown. E.g.
"too much recursion".
RangeError --- Creates an instance representing an error that occurs when a numeric variable or parameter is outside of its valid
range.
ReferenceError --- Creates an instance representing an error that occurs when de-referencing an invalid reference.
SyntaxError --- Creates an instance representing a syntax error that occurs while parsing code in eval().
TypeError --- Creates an instance representing an error that occurs when a variable or parameter is not of a valid type.
URIError --- Creates an instance representing an error that occurs when encodeURI() or decodeURI() are passed invalid parameters.
Context
Stack Overflow Q#23790509, score: 220
Revisions (0)
No revisions yet.