Day 16: Exceptions - String to Integer

  • + 0 comments

    Here's the ugly Typescript that doesn't use conditionals, lol.

    function fail() {
        throw new Error("Not an int")
    }
    
    function main() {
        const S: string = readLine();
        try {
            const num = Number(S)
            const test = !Number.isInteger(num) && fail()
            console.log(num)
        } catch (e) {
            console.log("Bad String")
        }
    }