Add used try catch to handle the exception

This commit is contained in:
Lev
2021-05-23 00:08:33 -05:00
parent 10bebe8f00
commit f812c0e244
2 changed files with 19 additions and 0 deletions

View File

@ -0,0 +1,19 @@
#include <string>
#include <iostream>
int main()
{
double d{}; //initializes to 0, dicated by the compiler
std::string s = "x1.6x";
try
{
d = std::stod(s);
}
catch(const std::exception& e)
{
//throw e;
std::cerr << e.what() << '\n';
}
std::cout << "d: " << d << std::endl;
return 0;
}