Add used try catch to handle the exception
This commit is contained in:
19
CM2005 Object Oriented Programming/Topic 3/3.3.1/test.cpp
Normal file
19
CM2005 Object Oriented Programming/Topic 3/3.3.1/test.cpp
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user