I myself is a Java-developer and now I'm trying to understand how to do it in the most efficient way in C++. After reading that answer I decided to write the following://Headers omittedclass integer_validator{public:    integer_validator(const char* const str);    bool is_valid();    long get_number();private:    bool valid;    long result;};integer_validator::integer_validator(const char* const str){     char *endptr;    result = strtol(str, &endptr, 10);    if(*endptr == '\0') valid = true;    else valid = false;}bool integer_validator::is_valid(){    return valid;}long integer_validator::get_number(){    if(!valid)        throw std::exception();    return result;}int main (){    integer_validator vv(123123);    integer_validator v(123123a);    std::cout << vv.get_number() << std::endl; //prints the number    std::cout << v.get_number() << std::endl;  //throws the exception}DEMOAnd it works perfectly fine. But I'm not sure about some things I did. Is it considered good to put any piece of logic into a constructor? I actually do the validation within the constructor's body and I use only the C-functions. So should I be afraid of throwing an exception during the construction in that case?
Understanding exceptions in a constructor (by the conversion C-string to long example)
c++
if(*endptr == '\0') valid = true;else valid = false;would be better as justvalid = *endptr == '\0';(or maybe even valid = !*endptr;, in the traditional C style).Note that this isn't a sufficient check.