Created
April 2, 2019 17:42
-
-
Save ryu1-1uyr/ee04e16dcb1b8c55ba92649c3c9de288 to your computer and use it in GitHub Desktop.
例外を使いたかった
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 FizzException() { | |
this.name = "Fizz" | |
} | |
function BuzzException() { | |
this.name = "Buzz" | |
} | |
function FizzBuzzException() { | |
this.name = "FizzBuzz" | |
} | |
const throwSomeException = number => { | |
if (number % 15 == 0) { | |
throw new FizzBuzzException() | |
} else if (number % 3 == 0) { | |
throw new FizzException() | |
} else if (number % 5 == 0) { | |
throw new BuzzException() | |
} else { | |
return number | |
} | |
} | |
for (let i = 1; i < 31; i++) { | |
try { | |
console.log(throwSomeException(i)) | |
} catch (e) { | |
console.log(e.name) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment