Catch exceptions in javascript:
Everyone is not thinking debugging JavaScript very painful, I also feel.
We'll use it if we can find a good way to help us debug JavaScript.
In fact, JavaScript can also catch exceptions, such as:
<div id= ' BBB ' style= "Display:none" >asdf</div>
<script>
function A ()
... {
Try
... {
var AAA = document.getElementById (' BBB ');
alert (Aaa.innertext);
}
catch (E)
... {
Alert (' ERROR ' + E.message + ' occurs in ' + E.linenumber + ' line ');
}
}
A ();
</script>
<div id= ' BBB ' style= "Display:none" >asdf</div>
<script>
function A ()
... {
Try
... {
var AAA = document.getElementById (' Sakdhglas ');
alert (Aaa.innertext);
}
catch (E)
... {
Alert (' ERROR ' + E.message + ' occurs in ' + E.linenumber + ' line ');
}
}
A ();
</script>
will be an error, JS exception e In addition to E.message and E.linenumber there is an important attribute E.name
E.name error type,
E.message the details of the error.
Error.name six values correspond to the information:
1. The use of Evalerror:eval () is inconsistent with the definition
2. Rangeerror: Value out of bounds
3. Referenceerror: Illegal or unrecognized reference value
4. SyntaxError: Syntax resolution error occurred
5. TypeError: Error of operand type
6. Improper use of urierror:uri processing function
So your JS code in the run to catch the exception code, even if the code error, will continue to run the code, will not stop, and the use of the exception to JS debugging also has some help.