Aloysious' Codefellows Reading Notes
<== Previous Lesson Next Lesson ==>
<== Home 🏠
There are two stages for Execution Contexts
Debugging is all about refining the process of deduction
The console narrows down where the error can be found the rest is on you
hint: where does the code stop running?….
. . . . . . . . . . . . . each can give you a line number and error message
7 Types of Native Errors in JavaScript You Should Know
Throw and Try to Catch
The try
statement lets you test a block of code for errors.
The catch
statement lets you handle the error.
The throw
statement lets you create custom errors.
The finally
statement lets you execute code, after try and catch, regardless of the result.
JavaScript catches adddlert as an error, and executes the catch code to handle it.
The try
statement allows you to define a block of code to be tested for errors while it is being executed.
The catch
statement allows you to define a block of code to be executed, if an error occurs in the try block.
The JavaScript statements try
and catch
come in pairs:
try {
Block of code to try
}
catch(err) {
Block of code to handle errors
}
When an error occurs, JavaScript will normally stop and generate an error message.
The technical term for this is: JavaScript will throw an exception (throw an error).
JavaScript will actually create an Error object with two properties: name and message.
The throw
statement allows you to create a custom error.
Technically you can throw an exception (throw an error).
The exception can be a JavaScript String
, a Number
, a Boolean
or an Object
.
If you use throw
together with try
and catch
, you can control program flow and generate custom error messages.
The finally
statement lets you execute code, after try and catch, regardless of the result
JavaScript has a built in error object that provides error information when an error occurs.
The error object provides two useful properties: name and message.
Property | Description |
name Sets or returns an error name
message Sets or returns an error message (a string)
Six different values can be returned by the error name property:
Error Name | Description |
EvalError An error has occurred in the eval() function
RangeError A number “out of range” has occurred
ReferenceError An illegal reference has occurred
SyntaxError A syntax error has occurred
TypeError A type error has occurred
URIError An error in encodeURI() has occurred
The six different values are described below.
Eval Error
An EvalError
indicates an error in the eval() function.
Newer versions of JavaScript do not throw EvalError. Use SyntaxError instead.
Range Error
A RangeError
is thrown if you use a number that is outside the range of legal values.
Reference Error
A ReferenceError
is thrown if you use (reference) a variable that has not been declared.
Syntax Error
A SyntaxError
is thrown if you try to evaluate code with a syntax error.
Type Error
A TypeError
is thrown if you use a value that is outside the range of expected types.
URI (Uniform Resource Identifier) Error
A URIError
is thrown if you use illegal characters in a URI function
Mozilla and Microsoft defines some non-standard error object properties:
Do not use these properties in public web sites. They will not work in all browsers.
JavaScript Errors w3schools.com
Complete Error Reference w3schools.com
From the Duckett JS book:
<== Previous Lesson Next Lesson ==>
<== Home 🏠