This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
<title>Document</title> | |
<link rel="stylesheet" href="style.css"> | |
</head> | |
<body> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function test() { | |
try { | |
return 10; | |
} finally { | |
console.log("finally"); | |
return 1; | |
} | |
} | |
console.log( test() ); // finally 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function test() { | |
try { | |
return 10; | |
} finally { | |
console.log("finally"); | |
return 1; | |
} | |
} | |
let a = test(); //finally | |
console.log( a ); // 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function test() { | |
try { | |
return 10; | |
throw "error"; // this is not executed, control goes to finally | |
} catch { | |
console.log("catch"); | |
return 1; | |
} finally { | |
console.log("finally"); | |
return 1000; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
let a = 10; | |
throw "a is block scoped "; | |
} catch(e) { | |
console.log("Reached catch"); | |
console.log(a); // Reference a is no defined | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
var a = 10; | |
throw "a is function scoped "; | |
} catch(e) { | |
console.log("Reached catch"); | |
console.log(a); // 10 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
// code with bug; | |
} catch { | |
// catch without exception argument | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function callback() { | |
// error code | |
} | |
function test() { | |
try { | |
setTimeout( callback , 1000); | |
} catch (e) { | |
console.log( "not executed" ); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function callback() { | |
try { | |
// error code | |
}catch | |
console.log("Error caught") ; | |
} | |
} | |
function test() { | |
setTimeout(callback, 1000); | |
} |