How do I validate int input using std::stoi() in C++?
<p>Is there a way to check if string input is convertible to int using <code>std::stoi()</code> in C++? (For example, could I check to see if an invalid_argument exception will be thrown?)<br/></p>

<p><em>An example that doesn't work, but hopefully explains what I'm trying to do:</em></p>

<pre><code>    string response;
    cout &lt;&lt; prompt;

    if (std::stoi(response) throws invalid_argument) { //Something like this
        return std::stoi(response);
    }
    else {
        badInput = true;
        cout &lt;&lt; "Invalid input. Please try again!\n";
    }
</code></pre>

<p><strong>Research:</strong><br/>
I've found several ways to check if a string is an int, but I'm hoping there is a way to do it using <code>std::stoi()</code> which I haven't been able to find yet.</p>