Day 16: Exceptions - String to Integer

  • [deleted]
    + 3 comments

    I did it in JS like so:

    // Hacky way to generate an exception
    var i = 1;
    try {
        i.toString(parseInt(S) * 0 + 2); // Fails on NaN
        console.log(S);
    } catch (err) {
        console.log("Bad String");
    }
    

    You're right though, this challenge is certainly a lot easier in strongly typed languages such as C# or Java.