This file contains 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
class MyError extends Error {} | |
try { | |
doStuff(); | |
} catch(err) { | |
if (err.name == 'MyError') { | |
console.log("This is my error"); | |
} else if (err.name == 'ReferenceError') { | |
console.log("Not my error. Ask the ReferenceError guys"); | |
} else { | |
console.log("I have no idea"); |
This file contains 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 { | |
throw new Date(); | |
} catch(err) { | |
console.log(err); | |
} | |
Tue Jun 25 2019 19:12:20 GMT+0300 (Israel Daylight Time) |
This file contains 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 { | |
throw “this is an error”; | |
} catch(err) { | |
console.log(err.name + ': ' + err.message); | |
} | |
> undefined: undefined |
This file contains 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 { | |
const y = x | |
} catch(err) { | |
console.log(err.name + ': ' + err.message); | |
} | |
> ReferenceError: x is not defined |
This file contains 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: | |
ratio = a / b | |
except ZeroDivisionError: | |
ratio = float(‘inf’) | |
except TypeError as e: | |
logger.critical(‘Got TypeError: %s’, e) |
This file contains 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 { | |
System.out.println(obj.charAt(0)); | |
} catch(NullPointerException e) { | |
System.out.println("NullPointerException.."); | |
} catch(MyAwesomeCustomException e) { | |
System.out.println("Caught an exception: " + e.myCustomInformation); | |
} |
This file contains 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 createPrintFunction(i) { | |
return function() { console.log(i); } | |
} | |
var functions = [] | |
for (var i = 0; i < 10; i++){ | |
functions.push(createPrintFunction(i)) | |
} | |
functions.forEach(f => f()) |
This file contains 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
var functions = [] | |
for (var i = 0; i < 10; i++){ | |
functions.push(() => console.log(i)) | |
} | |
functions.forEach(f => f()) |
This file contains 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
class A { | |
f = () => { console.log(1); } | |
g = () => setTimeout(() => this.f(), 1000) | |
} | |
function f() { console.log(2); } | |
var a = new A() | |
a.g() | |
> 1 |
This file contains 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
class A { | |
f() { console.log(1); } | |
g(){ setTimeout(function() { this.f(); }, 1000)} | |
} | |
function f() { console.log(2); } | |
var a = new A() | |
a.g() | |
> 2 |