Is it safe to ignore exception of boost::lexical_cast
when converting int
to std::string
?
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
- Converting glm::lookat matrix to quaternion and ba
- What is the correct way to declare and use a FILE
Exception raised by lexical cast when converting an
int
tostd::string
are not associated to the conversion, but to resource unavailable. So you can ignore this in the same way you ignore the exceptionbad_alloc
raised by operator new.As you say, I don't believe the cast can fail for the numerical types for conversion reasons - it can still fail because the string cannot be allocated, of course, but people don't normally catch that error except at the highest level of their code.
If you "ignore" an exception it will propagate back up the call stack until it is caught elsewhere, or it terminates the program, the point being you can safely not catch exceptions without worrying about you program continuing and doing unsafe/unknown things (as long as a "crash" to command prompt is acceptable error behaviour or you have some other way of dealing with unknown exceptions).
Unfortunately exception stack traces aren't so easy to get in C++, so creating useful error messages when exceptions aren't caught locally isn't always easy.