try..cath statement

try..catch


In the try..catch statement,

If an error occurs in try, no error will be reported.

The statement after the error in try{ }  will not be executed, but it will not affect the execution of the statement outside the try.

catch () { } will catch errors in try statements.

error.name, error.message

Error name and error message


E.g:

<script type="text/javascript">

console.log('text');

try {
	
console.log('a');
	
console.log(b); //Error statement, will not be executed
	
console.log('c') //try after the error statement will not be executed
	
}catch (e) {
	
console.log(e.name + " " + e.message)
	
//If there is an error statement in the try, it will be grabbed
	
}

console.log('text')  
// normal output

</script>

Console test:

QQ browser screenshot_20180315093705_65BE7B3F4F5B48e78BB2DD777EDED83F.jpg

This method will be very useful later on!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326044103&siteId=291194637